Eclipse + Ant + Subversion + SVNAnt

It has been a bit of a struggle to get the development team I am part of to move towards localised development, and have our source managed by version control software. Until now everyone has been developing on a single development box. Over the past few weeks, we have finally had the necessary software (Eclipse / Subclipse / ColdFusion / Apache) installed on all the developer machines and a Subversion repository setup.

I have spent the last couple of days importing all of the projects into the repository so that people can start checking out their projects and slowly move to working locally.

Now that we have all our code in the repository I started looking at using Ant to help automate some / all of our release management process. I had a quick look online and was pleasantly surprised to find SVNAnt that sounded like it would make this a breeze. Unfortunately connecting to SVN in Ant can be a bit of a hassle.

If you don’t have the subversion client installed on your computer you are supposed to be able to still connect using the JavaHL library. I could not get this to work. I found other people with the same problems, and tried all their suggestions, like copying jars and dll files into different directories, updating the windows %path% etc. Nothing I tried could get Ant to successfully connect to our repository.

A few people mentioned that install the subversion client was the only thing that they were able to do to get things functioning properly. I really didn’t want to install the command line client because that was kind of the point of having Subclipse. However, in the end having the ability to have Ant connect to SVN was more important.

Here are the steps that allowed me to get things working:

  1. Download and install the subversion client to [drive:\yourDirectory]
  2. Add the [drive:\yourDirectory]\bin directory to the windows path.
  3. Download SVNAnt.
  4. Extract 2 jars (you don’t need the svnjavahl.jar) to your Ant \lib directory (in my case D:\apps\eclipse\plugins\org.apache.ant_1.7.0.v200706080842\lib)
  5. In eclipse you need to add the 2 jars to the ant classpath (otherwise you will have to point to them in every script).
  6. Open up the external tools dialog (Run menu > External tools > Open external tools dialog)
  7. Under the classpath tab add the 2 external jars to the Ant Home entry.
  8. Apply your changes and restart eclipse.

Hopefully you should be able to connect to SVN now using an Ant build script. Here is a list of SVN tasks you can use in your script. Below is the test build script I used to test SVN access. Basically it will export a project from the repository.


<!-- svn repo url -->

<?xml version="1.0" encoding="UTF-8"?>

<project name="SVN Export" default="svn.export" basedir=".">

	<taskdef resource="svntask.properties" />

	<!-- svn repo url -->
	<property name="svn.url" value="[drive:\my project path]" />
	<property name="svn.exportPath" value="[drive:\export path]" />

	<target name="svn.export">
		<echo message="Exporting application files from svn repository:" />

		<input message="Please enter svn repo username:" addproperty="svn.username" />
		<input message="Please enter svn repo password:" addproperty="svn.password" />

		<svn javahl="false" username="${svn.username}" password="${svn.password}">
			<export srcUrl="${svn.url}" destPath="${svn.exportPath}" revision="HEAD" />
		</svn>

		<echo message=" ... finished exporting files." />
	</target>
</project>

About this entry