Team Explorer Everywhere - A Plug-in to access TFS from Eclipse (TeamBuild with Ant)
Posted by: Subodh Sohoni
in Category VSTS & TFS (Azure DevOps)
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.
Although I downloaded Maven, I did not do anything with it.
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:
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
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.
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.
I checked out the file and opened it in Eclipse. There was a new ItemGroup to call the Ant script
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.
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.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce the The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core. Use these concepts to deepen your existing knowledge of C# and .NET, to learn new features or to crack your next .NET Interview.
Click here to Purchase this eBook at a Discounted Price!