Team Explorer Everywhere - A Plug-in to access TFS from Eclipse (TeamBuild with Ant)

Posted by: Subodh Sohoni , on 6/4/2010, in Category Visual Studio, VSTS & TFS
Views: 93269
Abstract: "Team Explorer Everywhere" (TEE) is an Eclipse plug-in that is being provided by Microsoft with the Visual Studio 2010. In my previous article, I started out with the exploration of TEE and covered the grounds of Installation, configuration, accessing Team Project by connecting to a TFS and using source control of TFS for Java Project. In this article, I will wander deeper in the woods of using Team Build for Java projects created using Eclipse
In my previous article, Team Explorer Everywhere - A Plug-in to access TFS from Eclipse - Part I  we saw that 'Team Explorer  Everywhere' (TEE) is an Eclipse plug-in that is being provided by Microsoft with the Visual Studio 2010. The purpose of this plug-in is to provide access to Team Foundation Server 2010 from Eclipse which is one of the most popular IDEs for Java development. In this way now the projects that are being developed using Java technology can also leverage the benefits like integrated services for workitem tracking, source control, build management, reporting and portal for the team collaboration. In my previous article, I started out with the exploration of Team Explorer Everywhere (TEE) and covered the grounds of Installation, configuration, accessing Team Project by connecting to a TFS and using source control of TFS for Java Project. In this article I will wander deeper in the woods of using Team Build for Java projects created using Eclipse. If you haven't already, you can download the latest TEE installable in the .zip format from Microsoft site.
I guessed that for Java Project to build, the build engine will require to know the compiler and its location. It is also quite obvious that Java project does not have the kind of project structure that is required by Team Build. It does not have the solution, .sln file and Project. All of these pointed towards the fact that I may not be able to use Team Build workflow or MSBuild based build definition directly. A little bit of research revealed that Microsoft has published a power tool called “Microsoft Team Foundation Server 2010 Build Extensions” that provides extensibility to use existing Ant or Maven build scripts through Team Build. I downloaded that from here . In the prerequisites it is very clearly mentioned to have following installed on the same server that is hosting the Team Foundation Build Agent:
·         Java JDK (the latest one available from your JDK vendor is recommended)
·         Ant (if Ant support is required).
·         Maven 2 (if Maven support is required)
I downloaded latest JDK (V 6 update 20) from here and installed it on a virtual machine that already had TFS 2010 and Visual Studio 2010 installed. Next task was to set the path. In the Environment section of System Control Panel, I set the variable JAVA_HOME to the directory where Java was installed (C:\Program Files\Java\jdk1.6.0_20 in my case). Then set the path to contain JAVA_HOME\bin folder.
I decided that I will experiment with Ant primarily and may be try Maven if it seems interesting. I downloaded latest version of Ant (V 1.8.1) from Apache website. I opened the downloaded .zip file under C:\Program Files\Apache folder. Then created the ANT_HOME variable in the environment and set its value to the folder that contains bin folder of Ant. In my case it was C:\Program Files\Apache\apache-ant-1.8.1-bin\apache-ant-1.8.1. Then I added the path of Ant bin to environment PATH.
System
Although I downloaded Maven, I did not do anything with it.
Now I began with the same Java project that I had started with. In that project I added a file with the name build.xml. I also added the association of Ant Editor in Eclipse to .xml extension. Details of setting up Ant editor are provided at http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.user/reference/ref-anteditorprefs.htm .
Now I needed to write an Ant script that will compile my Java project and I also wanted it to create a Jar of the output. I started out writing the first tag in the file and Eclipse obliged me by asking if I want a standard 2 target Ant script. I was delighted to have it since I had only vague idea that Ant scripts are conceptually similar to MSBuild scripts. I took that offer made by Eclipse and got the stubs of the script and targets in it. With some trial and error I created a script that looked like following:
Script
I did not know how to set source and destination locations but made an assumption that the calling target will provide those properties when it calls those targets. Another decision I made was to keep it under the same folder as the Java project so that it will be also checked-in. Although I made that decision instinctively, later on I realized that it is a necessity to keep this build script under source control under the same project.
Now my problem was that I could not test this script within the Eclipse itself since my source was on TFS, checked-in. I had to use Team Build to provide the source and destination.
I had a hunch that I should be able to add the Ant targets in the TFSBuild.proj file if it existed now. Since last more than six months I had played only with the workflow designer and custom activities in Team Build 2010 so did not remember if it still maintained TfsBuild.proj file. I thought that it should be there since I had come across the upgrade template that allowed the old version builds to be upgraded to the 2010. I started out by opening the tried and trusted Visual Studio 2010 and opened the wizard to create new build definition. That’s as far as I did go that route since I immediately realized that I had no solution and no project. I abandoned that attempt.
Now I reopened Team Foundation Server Exploring perspective with Team Explorer view in Eclipse, with my team project in it. Right click on the Builds node gave me an option to create new build definition
TeamFoundation
On the click of that option, the wizard similar to one that existed in TFS 2008 started. It accepted regular options of Name, Workspace, build server and drop location and also allowed me to create the Tfsbuild.proj. This is where the major difference from regular wizard was observed.
CreateBuild
This wizard asked me to select either a Ant script or a Maven script that will be the base for MSBuild script. Here the decision that I had taken to keep that script under source control of the same project was vindicated. It was possible to select from only the scripts under source control under that project.
After I finished the wizard it created the TfsBuild.proj file under the source control under the regular folder of TeamBuildTypes.
SourceControl
I checked out the file and opened it in Eclipse. There was a new ItemGroup to call the Ant script
AntScript
An import tag that needs to be changed in the file is (after change) as follows:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\BuildExtensions\Microsoft.TeamFoundation.Build.Extensions.Ant.targets" /> 
 
The default path that is provides is a carryover from the old Teamprise days.
Finally I queued the build as usual and it did execute to create the required class file and Jar as configured in the Ant script and executed by MSBuild engine.
Summary:
In the last two articles we have seen how the concept of Integrated Foundation Services provided by Team Foundation Server 2010 can be used and leveraged for higher productivity for development of projects in the Java technology in the popular IDE of Eclipse.
Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles
Subodh Sohoni, Team System MVP, is an MCTS – Microsoft Team Foundation Server – Configuration and Development and also is a Microsoft Certified Trainer(MCT) since 2004. Subodh has his own company and conducts a lot of corporate trainings. He is an M.Tech. in Aircraft Production from IIT Madras. He has over 20 years of experience working in sectors like Production, Marketing, Software development and now Software Training. Follow him on twitter @subodhsohoni


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Undefined on Tuesday, July 20, 2010 6:47 AM
Good article.. I have a question regarding licenses for team explorer everywhere. We already have team explorer CAL purchased to use team explorer with TFS . Can the same license used here or do we need separate licenses
Comment posted by Subodh Sohoni on Wednesday, July 21, 2010 9:01 AM
Since the CALs are issued for accessing TFS and not for which client are you accessing it from, you can use the existing CAL to access TFS from TEE. What you should take care of is not to exceed concurrent connections to TFS that exceed the total CALs that you have.
Comment posted by Ismail Ahmed Syed on Friday, February 4, 2011 11:43 AM
I followed the way u showed but my build is failing when it is loading antcontrib.properties file whereas when i open the command prompt and run the build(ant build ) it works perfectly fine. I used the same user in both the cases(tfs build account), Can you please help me in this regard. I appreciate your help for helping me out
Comment posted by Sen on Monday, October 17, 2011 6:57 AM
Hello Sir,

Thanks for the post on eclipse plug in. I have a query related to eclipse IDE.
Currently we have written custom control and check in policies for WIN forms and web access. But we currently use windriver(eclipse IDE) tool to access TFS (use Team explorer everywhere) and here the custom control and policies we created are not reflected. Please let us know how to deploy the custom control we created as DLLs in eclipse plugin to reflect in IDE. Or whether we should write new custom control in JAVA..?

Thanks & Regards,
Sen
Comment posted by Subodh Sohoni on Thursday, November 10, 2011 2:12 AM
The custom controls of WIN Forms and web access written in .NET do not work for Eclipse even if you are working on MS platform. MS has published a Java SDK for TFS that has a sample of custom control for eclipse. You will find it at http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=22616. You will have to develope your own new custom controls using this SDK.
Comment posted by Gabriele on Wednesday, January 11, 2012 4:57 AM
Hi,
I am using TFS with the eclipse plugin (TEE), and build extension which is illustrated in this article. I found problems in the build. The result is 'partially succedeed', but I did not log on to refer to understand the reason for the error ..
how can I proceed?
this is my build.xml
<project name="ProvaBuild" default="init" basedir=".">
     <description>
         Sample JUnit Tests
     </ description>
   <! - Set global properties for this build ->

   <property name="project_name" value="junitSamples"/>
   <property name="src" location="src"/>
   <property name="build" location="bin"/>
   <property name="dist" location="dist"/>
   <property name="lib" location="lib"/>
   <property name="res" location="res"/>
   <property name="reports" location="reports"/>
  
   <! - Various names of the distributable files ->
   <property name="jar_name" value="${project_name}.jar"/>
   <property name="war_name" value="${project_name}.war"/>

<! - Supporting targets ->

<target name="init" description="initialize the build environment">
     <! - Create directory structures ->
<mkdir dir="${build}"/>
<mkdir dir="${lib}"/>
<mkdir dir="${dist}/lib"/>
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/>
</ target>
  
</ project>
Comment posted by Imad Ghaleb on Monday, January 23, 2012 1:21 PM
Very Useful info. How one can build multiple Java projects on a build system with different JDK level?. Is there a way to set the JAVA_HOME variable in the build definition instead of defining it as Windows system variable?.

Thanks
Imad

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel