Using Team Foundation Server 2010 Build Service for Java Project using ANT
Posted by: Subodh Sohoni ,
on 11/22/2011,
in
Category Visual Studio, VSTS & TFS
Abstract: In this article, we will explore how to use TFS 2010 for Build Management of Java Projects. We will use Eclipse based plug-in named Team Explorer Everywhere for creating a build definition that encapsulates an ant script and provides manageability to it.
In a previous article, I walked you through the process of using the various features related to Version Control of Team Foundation Server 2010. In this article now I will cover use of another service of TFS 2010 – Build Management for Java Projects. We will use Eclipse based plug-in named Team Explorer Everywhere for creating a build definition that encapsulates an ant script and provides manageability to it. Team Explorer Everywhere can be downloaded over here.
Step 1: I assume that you have installed JDK, Eclipse and Apache Ant on your machine. If you have not configured environment variables, add the environment variable JAVA_HOME as JDK Path and add %JAVA_HOME%\bin; to the path. Also set the environment variable ANT_HOME to the ANT folder. In my case it was C:\Program Files\Java\Apache-Ant-1.8.1, so I added %ANT_HOME%\bin; to path.
Step 2: Install Microsoft Team Foundation Server 2010 Build Extensions that is downloadable from http://visualstudiogallery.msdn.microsoft.com/2d7c8577-54b8-47ce-82a5-8649f579dcb6/ . It gives the ability to use Team Foundation Server 2010 Build service to do builds based upon Ant or Maven.
Step 3: To know how to create a Java Project in Eclipse and add it to TFS 2010 Version Control, you can go through my article -
To know how to create a Java Project in Eclipse and add it to TFS 2010 Version Control, you can go through my article -
Using Team Foundation Server 2010 Version Control for a Java Project
Step 4: Let us now create build definition and queue build. To create an Ant script, add a new file to the Java project. Name it as build.xml
Step 5: Add the following code in this xml file
<project name="PwdValProject" default="compile">
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="build/classes"/>
<javac srcdir="." destdir="${DropLocation}\${BuildNumber}"/>
</target>
</project>
Step 6: Checkin all the files
Step 7: Open the TeamFoundation Server Exploring perspective and expand the Tailspin Toys project. Select Builds node, right click on it and select New Build Definitions

Step 8: Build Definition Creation wizard is started. In the first page of this wizard, enter the name of the build definition - Password Validator Build. You may optionally enter some description.
Step 9: Observe all the automation triggers on the trigger page. Keep the trigger to manual only but even if you select any automated trigger, it can be manually queued whenever required.

Step 10: Let the workspace to be used, be the default. On the Build Defaults page enter the drop location as \\MachineName\ShareName . If the shared folder does not already exists, then create and share it.
Step 11: On the Project File page of the wizard, browse to the Password Validator folder and then click the Create button

Step 12: Select the option of MsBuild Configuration from existing Ant script and click Next

Step 13: Drill down to the Build.xml file that you had checked in during the earlier step and Click Finish button

Step 14: Let the retension policy be as it is

Step 15: Click OK to complete the build configuration and close the wizard. You will find Password Validator Build definition appearing in the Builds folder of Team Explorer.

Step 16: Right click on that build definition and select Queue New Build

Click on the Queue button in the next page.

You can view that the build is started and you will also be able to view the results once the build run is over.
Give me a +1 if you think it was a good article. Thanks!