Alexander Vanwynsberghe

"There is nothing impossible to him who will try"

TFS 2012 + Ant: Unable to access ant-launcher.jar

Today, I was was trying to create a build definition to run an Ant build from a Java project in Eclipse. First of all, I installed the brand new Team Explorer Everywhere for TFS 2012 RC (which looks really good!). Next step was to install the Build Extensions (to support Ant and Maven 2/3 builds). The installation went perfect, no problems at all.

Next step is to install Winant to support Ant builds on a Windows operating system. I also installed the Java SDK (including the JRE, otherwise you cannot run Eclipse). When all this was finished, I created my build definition like I normally do (I made a blog post about this a while ago).

Only.. there was a quite strange behavior when I queued my build. It only took 2 seconds. According to the build output, the Java project was successfully built, but the build was red. When I looked at the logs, I found this error:

Error: Unable to access jarfile C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\BuildExtensions\apache-ant\lib\ant-launcher.jar

This is strange, but on the other hand correct because ant-launcher.jar doesn’t exist on that location.

Solution: When you install the Java SDK and Winant, it creates 2 environment variables. The thing is that it creates ‘User’ variables, and not ‘System’ variables. So what you have to do is create 2 system variables and append the bin paths to the ‘path’ system variable. In my case:

“ANT_HOME = C:\Program Files (x86)\WinAnt”

“JAVA_HOME = C:\Program Files\Java\jdk1.7.0_04”

“Path = …………………;JAVA_HOME%bin;ANT_HOME%bin;”

Next, restart you build service (to catch the new added system variables) and queue your build. As you can see: Issue solved :-)

TFS build automation for a Java project using Ant

builddefinition06_2

In a previous article, I walked through the process of installing and using Team Explorer Everywhere on an Eclipse environment. That way, you can use TFS for your Java development. In this article, I will cover the process of how you can use the Team Foundation Build Automation to automate your Java builds using Ant. I’ll guide you through all the necessary steps and give you some personal experiences.

First of all, you need to have Team Explorer Everywhere installed (more about that in my previous post). If you have this, you’re ready to go.

Getting started with Java and Ant

To start, let me explain you what Ant is and how you can use it.

Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects. Ant stands for ‘Another neat tool’ and was released at first in 2000.

The Ant build definitions are declared in a build.xml file. The root node of a build.xml file is ‘project‘, where you define the name of the project and the default ‘target’. This target will be executed when you build your project. The child-nodes of a project are those ‘target‘ definitions. You can define as many targets as you want. For example ‘clean’, ‘compile’, ‘jar’,.. Each target can have its dependencies. You can define that the ‘jar’ target depends on the ‘clean’ and ‘compile’ target. That way, you have a sequence of executing. Let me give you a really basic example:

When you use Eclipse, you can use the Ant window to visualize the Targets of your build.xml file. (Link your build.xml file using the ‘add build files’ button) Using this window, you can also execute a specific Target by double-clicking on it. Be sure that you do a check-in of your build.xml file!

Build01

Create a build definition

Now you have Ant up and running, we can define our TFS build definition. This build definition will take care of the build process on our TFS build controller. If you want to learn more about build controllers and build agents on TFS, take a look at this article.

1. Open the Team Foundation Server Explorer in Eclipse (using the Team Foundation Server Explorer perspective). Select Builds node, right click and select ‘New Build Definition’

2. In the new window, the first thing you have to do is provide a build definition name and a description

Builddefinition01

3. The next step is to define the build trigger. Choose the option that suits you the best. In my case, I selected a Continuous Integration Build.

Builddefinition02

4. The following step is the definition of your working folders. This is the mapping that the build server will use. (If you defined a custom workspace mapping on your local machine, you can also copy this using the ‘Copy Existing Workspace’ button.

Builddefinition03

5. Select your build controller and the place where to output your files. Note that even on Linux, if you use a network location, use ‘\location’ and not ‘smb://’ (which you would normally use on a linux machine to access a Windows share). That’s because the build-controller is running on a windows machine, and this controller uses the network path you define there.

Builddefinition04

6. On the ‘project file’ section, you can define which ‘build’ you want to use. Click on the ‘Create’ button to start a new wizard. The first step in this wizard is to select which build file you currently have. In our case this is an Ant build file. Select this an click next.

Builddefinition05

7. The next step is to select your build.xml file, which is already in your project. Click finish to close this wizard.

Builddefinition06

8. As you can see now, the wizard tells you that there was a MSBuild project file found. That file was automatically created by the previous wizard. Note that this file is located in a folder called ‘TeamBuildTypes’. If you want to understand what’s in that TFSBuild.proj file, take a look at this document.

Builddefinition07

8. The last step is to define your Retention policy. There you can select some numbers of how many files are kept when a build succeeds, fails,..

Builddefinition08

9. Click Ok to create your Build Definition. You Should now see your new build definition in the list.

Build server changes

To summarize: We have a Java project, an Ant build.xml, a TFS build definition based on the Ant build file. The next step is to prepare our TFS Build server so it will be able to build Java projects based on Ant/Maven2. For that, you will need the Team Foundation Server Build Extensions Power Tools. They can be download here. This extensions provide the ability to execute Ant or Maven 2 builds from Team Foundation Server and publish the results of the build along with any associated JUnit test results back to TFS.

After you have installed this on your build server, be sure that you have the correct JDK and Apache Ant installed. Next thing you may not forget is set the correct environment variables to your (build) system. I spend quite a while looking for the correct one, so here they are:

Add a system variable ‘ANT_HOME’ with value ‘C:Program FilesWinAnt’ (or where Ant is installed). Next add a system variable ‘JAVA_HOME’ with value ‘C:Program FilesJavajdk1.6.0_25’ (or again where your jdk is installed). The last step is to edit your system variable called ‘Path’. At the end of this value (it should already contain a bunch of other settings) you add ‘;%JAVA_HOME%bin;%ANT_HOME%bin’.

Environment

Now you’re ready to go. The build server can now execute Ant builds.

Ant build usage with TFS

The nice thing about using Ant with TFS is that the TFS build will provide some extra parameters that can be used in your build. For example you have BinariesRoot, BuildDefinitionName, BuildDirectory,… You can use this parameters in your Ant build definition.

I’ll combine the previous explanation with the fact that you also have ‘conditional’ parameters in your Ant build file. What I mean is that you can declare variables, depending on the fact that the variable is or isn’t defined. For example, if you run your Ant build inside your Eclipse, you have no ‘BinariesRoot’ variable available. That’s because this is provided, additionally, by our TFS build script. What we  can do is the following:

<condition property=”dir.output” value=”${BinariesRoot}”>

<isset property=”BinariesRoot” />

</condition>

<property name=”dir.output” value=”${basedir}/output” />

So if the ‘BinariesRoot’ variable exists, then use it, otherwise use the ‘basedir’ instead. That way, you can create your Ant build so that it does run local, but also on the build server.

Run your build

Now you have all the parts completed, it’s time to execute your build. Using your Team Explorer in Eclipse, right-click on your build definition and click ‘Queue new build‘ (or do a code check-in if you defined a CI build). Now you should see the build running in the ‘Build Explorer Window’. Double-click on the build to see the results. You also have a log, containing the output of the Ant-build. If you go to the drop folder, you should see your output files.

Buidexecute
Buildexecute02

Now it’s up to you to change your Ant build file, and play with some targets. In a next post, I will explain how you can define JUnit-tests in your Java application, and also link the results to your TFS build, and even watch the results in Visual Studio.

Thanks for reading!

Hosted TFS with TEE11 using Eclipse on Linux

A while ago, I made a blog post about how to access TFS2010 with Eclipse. Now the cool thing is that there is also a new version of Team Explorer  Everywhere 11 (TEE11) to be used with Visual Studio Team Foundation Server 11 Developer Preview, so this also includes the hosted TFS version (tfspreview.com, where I still have one invite left).

As I have an account on the hosted TFS preview, I definitely wanted to connect my brand new Ubuntu 11.10 distro with my brand new Eclipse 3.7 IDE. I will not explain each step of the installation process, as they are described in my previous post.

You can get the TEE11 download here, or using your TFS preview (Administration -> 3. Download software).  You will need the ‘TFSEclipsePlugin-UpdateSiteArchive-11.0.0-CTP1.zip‘ file.

Once the bits are downloaded, install the Eclipse plugin (Help -> Install New Software). After the plugin is installed, go to Window -> Show View -> Other -> Team Explorer and select the TFS specific windows you need.

The next thing you want to do off course is connect to your shiny hosted TFS. In the Team Explorer, click on plus-sign and on the server window, click on the add button. In this window, add the URL of you TFS server in the correct format. If you want to connect to your hosted TFS, enter ‘https://yourname.tfspreview.com’. This will automatically disable the connection details window. Next step, click on OK.

If you’re using Ubuntu 11.10, you will get a nice error window.. Auch..?

Tfs11_linux

I was not really sure what the problem was. Something about ‘XULRunner’, but I never heard about that before. So I posted an issue on the MSDN forum. Because I really wanted to know what was wrong and I started a quick wiki-search:

XULRunner is a runtime environment developed by the Mozilla Foundation to provide a common back-end for XUL-based applications. It replaced the Gecko Runtime Environment, a stalled project with a similar purpose. All XUL-based applications like Mozilla FirefoxMozilla ThunderbirdSongbird, …run on XULRunner.

So from what I understand is that XULRunner is a runtime environment where you can render things, like Firefox uses it to render webpages. The error I had was indeed when the plugin wants to open a windows to show the Windows Live login screen. Ok, but how to solve my problem, as Ubuntu 11.10 has XULRunner by default?

After some google work, I found out that TEE11 requires xulrunner-1.9.2, which is not installed anymore on Ubunutu 11.10. I will tell you how to install this, as it’s not just “apt-get install xulrunner-1.9.2, which will not work by default.

The first thing you have to do is adding a line to your /etc/apt/sources.list
Go to your terminal, and enter:

sudo gedit /etc/apt/sources.list

After entering your password, it will open the gedit texteditor. Just add the following line to the end of the file:
deb http://security.ubuntu.com/ubuntu lucid-security main  

Gedit

This line will allow you to apt-get on the security repositories of Ubuntu. Now you can open your terminal, and simply type:
apt-get install xulrunner-1.9.2

This will install the package on your machine. If this doesn’t work, you can also download the package as .deb file and install it by double clicking on the package, and follow the steps of the Ubuntu software center.

Swc

Next thing is restart your Eclipse IDE, a try to add a new TFS server. Now you should see the Authentication window like you have in VS2010 SP1 (with KB2581206)

Liveid

All right, mission accomplished! Now you can do whatever you want with TEE11 like source control, workitems, builds,..

Teexpl

Just wanted to say thanks to Shaw Terwilliger who gave me the following explanation about the issue:

I’m glad you figured this out quickly, I was just about to post the same work around.  We finished our TEE 11 CTP before Ubuntu 11.10 was released, and we depend on the Mozilla browser via xulrunner for this control.  Shortly after Ubuntu 11.10 was released, xulrunner wasn’t available in the repositories but the xulrunner-1.9.2 from 11.04 installed cleanly and works.

We’re investigating Ubuntu’s plans to continue shipping xulrunner in future releases, and may make some changes in our next release to work with the Webkit browser (the default in Eclipse 3.7 on Linux/GTK).

Accessing TFS2010 from Eclipse

One of the cool things about using Team Foundation Server is the fact that it’s not technology bounded. What I mean about that, is the fact that you’re not tight to Visual Studio as IDE and that TFS can also be used to build non-microsoft solutions like Java. In this blogpost, I would like to describe how you can use Eclipse to manage your TFS environment.

Tee

Last year, Microsoft released a plug-in for Eclipse, originally called TeamPrise but now it’s ‘Team Explorer  Everywhere‘ (TEE). Using this plug-in you have access to TFS 2010 from Eclipse, which is a very popular IDE. Projects using Java/PHP/.. can now also leverage the benefits like workitem tracking, source control, build automation, reporting and web-portals. 

This is a quick overview of how to install TEE. First of all, I will use Eclipe on a Ubuntu environment (just to show that it also work on Linux machine). I downloaded the latest Ubuntu release (which is really cool, btw) and created a Virtual Machine to install Ubuntu. After installation of the OS, you get this nice welcome screen:

Login_ubuntu

Next step is to install Eclipse. Very simple, just download the Eclipse (3.7-Indigo) environment you want (for Java, classic, PHP). In linux, this will be a tar.gz and in Windows a normal .zip file. All you have to do after downloading is unzip/untar the file and put it in C:/eclipse or /home/.. (whatever you want). The next thing that you have to check is that you have a JRE/JDK installed. (download on oracle.com). Now it’s time to run Eclipse:

Eclipse

The next thing we want to do is install TEE SP1 (SP1 is a full package, there is no need for the non SP1 version).You can download the connector using your MSDN subscription, or using the public download url. You can download all 3 files, but actually you only need the file TFSEclipsePlugin-UpdateSiteArchive-10.1.0.zip. When the download is finished, go to Eclipse and select ‘Help -> Install New Software’. This opens a dialog where you can install additional plugins/connectors.

Click on the ‘Add..’ button to add a new repository. Enter a name, like ‘TFS connector’ and click ‘Archive’ to select the downloaded zip file. Select the new item you’ve just downloaded and click next. Follow the wizard, accept the license and click on the ‘Restart Now’ button.

When Eclipse is restarted, you don’t see many changes. The TFS related windows are more or less hidden by default. You can show them by selecting ‘Window -> Show View -> Other -> Team Foundation Server‘. There you can select the windows you want.

Now we have TEE installed in Eclipse, we can start using it. Create new project and add some awesome codefiles to it (yes I use PHP in my examples :$). If you did that, we can add the project to our Team Foundation Server. Right-click on your project and select ‘Team -> Share Project‘. There you get a dialog asking you for the TFS settings (Url & credentials). Supply them correctly and click Next.

Note: If you use Active Directory to connect, enter the correct domain and complete the username with your windows username. Also be aware that if you check ‘Save password’, the password will be saved in plain text on your system!

Then you get a list with your team projects, select the team project you need and click Next. In the list you see now, click the Team Foundation Server workspace to which your project will be connected, and then click Next. (You can offcourse also change the default values from your workpace). The last step is to select the folder for you shared projects (the project folder path). Click Next. In the last dialog, you have an overview of your selected settings, and now just click Finish 

Now that the project is added, we can do a check-in using the ‘pending changes’ window. If you look there you will see that all files associated with your project are marked as ‘add’. Now add some comments and click ‘Check In‘.

Eclipse14

If you return to Visual Studio, and do a ‘Get latest version ‘ on your project, you should see your files from your Eclips project. 

Eclipse15

Ok, so now we can do (allmost) all things we can do with the ‘normal’ Visual Studio Team Explorer. We have our team explorer, we can manage our sourcecontrol, manage our build, our workitems, merge files on update conflicts,… The only restriction I found was that there is no possibility to use the braching/merging actions/overview like you can in the regular TE. Other than that, I think it’s quite similar to the Team Explorer from Visual Studio. Some screenshots:

This was an overview about how to install TEE on Eclipse. In a next blogpost, I’ll cover how you can build a JAVA project using ANT/MAVEN with the TFS buildserver (using the Microsoft Team Foundation Server 2010 Build Extensions). Stay tuned!

Some reading material:
Five Hidden Features in Team Explorer Everywhere 2010 SP1
Team Explorer Everywhere 2010 SP1 is Available