ANT Builds and Subversion (SVN)

As I have mentioned in a previous blog entry, I have come to love using ANT in my development environment. One of the things that I like about it is how well it integrates with my Subversion repository using SVNAnt. If you are not using either ANT or Subversion, you owe it to yourself and your team to check it out.

Here we'll go over a simple build script that exports application files from the Subversion repository into a local folder in the CFEclipse project. You can then view the following entry on how to ftp that into your production/staging server.

First we need to make sure that your ANT install has the necessary SVNAnt jar files. You can download them here: http://subclipse.tigris.org/svnant.html. Once you unpack the svnant-1.0.0.zip file, you'll find threee jar files: svnant.jar, svnClientAdapter.jar, svnjavahl.jar. Place them on your [ANTInstall]/lib* folder.

Once you have the jar files in place, you can define them in your build file's property section like so:

<!-- svnant lib -->
<property name="svnant.lib" value="lib" />
<property name="svnant.jar" value="${svnant.lib}/svnant.jar" />
<property name="svnClientAdapter.jar" value="${svnant.lib}/svnClientAdapter.jar" />
<property name="svnjavahl.jar" value="${svnant.lib}/svnjavahl.jar" />

Followed by this path definition after all your properties have been defined:

<!-- path to the svnant libraries. Usually they will be located in ANT_HOME/lib -->
<path id="project.classpath">
<pathelement location="${svnjavahl.jar}" />
<pathelement location="${svnant.jar}" />
<pathelement location="${svnClientAdapter.jar}" />
</path>

Now all you have left to do is add the following task definition:

<!-- load the svn task -->
<taskdef resource="svntask.properties" classpathref="project.classpath"/>

Now you are all set! You can now call tasks like the following export target:

<!-- define properties -->
<!-- svn repo url -->
<property name="svn.url" value="http://[mysvnhost]/svn/repo/myprojectFiles/" />
<property name="svn.exportPath" value="[yourDirectory]:\\[pathToYourCFEclipseProject\\build" />

<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" />
<mkdir dir="${svn.destPath}" />
<svn username="${svn.username}" password="${svn.password}">
<export srcUrl="${svn.url}" destPath="${svn.exportPath}" revision="HEAD" />
</svn>
<echo message=" ... finished exporting files." />
</target>

That's it. No more running command line tasks to get your subversion commands. For additional info and other SVN tasks you can go to http://subclipse.tigris.org/svnant/svn.html.

Related Blog Entries

Comments
Phill,
This is GREAT content! I will certainly bookmark this for later. Thanks a ton for making this and keep up the good work!
# Posted By Nathan Strutz | 1/30/07 2:06 PM
I just posted an article on my blog regarding the SVN passwords:

http://www.thecrumb.com/2007/02/07/using-ant-while...

I never liked that the Ant input task left the password exposed...
# Posted By Jim | 2/8/07 10:46 AM
Jim,

Very interesting! Thanks for the link. I'll be sure to check it out...

Cheers..
# Posted By phill.nacelli | 2/8/07 12:51 PM
The best use of this that I see (and we are currently using in our own builds) is to take the repository version number as a build number. In our current build system this gets injected into various JAR files so we can compare versions.

At the moment I'm working on an 'official' un-attended build process that automatically updates minor version numbers based on changed files in a directory (as determined by this SvnAnt library with a restriction on the username - we use the user 'build' to do automatic nightly builds which are flagged as 'official' as opposed to 'developer' builds).

All in all integration between ANT and whatever code repository system you use is beneficial - SvnAnt seems to provide a lot more useful information than any other that I have seen (and Subversion itself seems to be one of the more useful code repository tools available).

Cheers,
Ghost

PS: Seriously - your site is a good indication of why the Captcha mechanism sucks - when and where should I use capitals, what is the differentiantion between letters (eg O, o, i, I and numbers eg 1, 0). I have tried multiple times only to find out the first 'n' times are probably due to not providing an email address (which is not marked as compulsary - and the error message is not clearly indicated either). Now I'm getting 'Captcha' errors, but no indication of what I should input from the vague image that is displayed. Is it case sensitive? Are numerals expected and/or allowed? Who knows. Anyway - end of rant. I'll try again.
# Posted By Ghost | 3/12/07 7:02 AM
Another go at the Captcha - this time just long enough to say 'Please excuse spelling errors in the previous comment' - I was getting so frustrated that I skipped the spelling check on the input field.

Cheers,
Ghost
# Posted By Ghost | 3/12/07 7:04 AM
First thanks for sharing the code.

Please clarify "Place them on your [SVNInstall]/lib* folder.".

What is [SVNInstall]/lib* folder? After installed Subversion, I see a folder "C:\Program Files\Subversion". Is this the SVNInstall folder? Under the "C:\Program Files\Subversion" folder, there is not "lib" folder
# Posted By fuji | 4/1/07 8:10 AM
@fuji Sorry for the confusion, it should have been [ANTInstall]/lib folder. Nice catch...

Basically the folder that you have ant running with Eclipse. If you are using Eclipse's default ANT install, it should be in the plugins folder of Eclipse (ie. C:\Program Files\Eclipse\plugins\org.apache.ant_1.6.5\lib).

Let me know if you have any more problems or questions.

Cheers...
# Posted By phill.nacelli | 4/1/07 11:51 AM
Please help. I can't make it work when I followed the steps. I keep getting the error "Could not load definitions from resource svntask.properties. It could not be found."

I placed the 3 svn *.jars in C:\eclipse\plugins\org.apache.ant_1.6.5\lib. I don't know what else to check.


Here's a part of my build.xml:

   <property name="svnant.lib" value="C:\eclipse\plugins\org.apache.ant_1.6.5\lib" />
   <property name="svnant.jar" value="${svnant.lib}/svnant.jar" />
   <property name="svnClientAdapter.jar" value="${svnant.lib}/svnClientAdapter.jar" />
   <property name="svnjavahl.jar" value="${svnant.lib}/svnjavahl.jar" />

<path id="project.class.path" >
<pathelement path="${env.classpath}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="${src}"/>
<pathelement location="${build}"/>
<pathelement location="${svnjavahl.jar}" />
<pathelement location="${svnant.jar}" />
<pathelement location="${svnClientAdapter.jar}" />
</path>

   <!-- load the svn task -->
   <taskdef resource="svntask.properties" classpathref="project.class.path"/>
# Posted By alex | 7/4/07 10:38 PM
Thanks for the information as it is very helpful along with the link to the download.
# Posted By Atlanta Real Estate | 2/4/08 8:58 PM
Cool link!! It was very much useful for our project.Keep post such kind informatic links.

cheers
-Nags
# Posted By Nags | 2/21/08 10:25 AM
# Posted By funnypics | 3/31/08 1:10 AM
# Posted By Allerst | 4/7/08 10:58 PM
# Posted By nelson | 4/21/08 5:28 AM
Excellent site, man and I really appreciate it! <a href="http://fxhqproject.com/">mp3 download</a>
# Posted By mp3 download | 4/21/08 10:04 PM
Your site has very much liked me.
I shall necessarily tell about him to the friends. http://echocct.org
# Posted By Online | 4/21/08 10:09 PM
Thanks for your blog !
# Posted By Voyance gratuite | 4/24/08 2:03 AM
Your site has very much liked me. I really appreciate it! http://seduhairstyles-nt.blogspot.com
# Posted By Sedu hairstyles | 4/25/08 1:48 AM
Hello! Excellent site. Thanks for job!
# Posted By Hamster | 4/25/08 10:54 PM
Hi! Nice post, man. I have always enjoyed reading your site. Thanks you!
# Posted By Baby nursing pillow | 4/27/08 10:21 PM
# Posted By Tadalafil | 4/28/08 11:51 PM
# Posted By cheap | 4/28/08 11:52 PM
I had trouble finding this information on the Internet!
Thank you for taking the time to post!
http://www.j-aide.com
http://www.voyanceo.fr
# Posted By Jeff | 4/30/08 2:48 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.003. Powered by ColdFusion Server v8,0,0,176276.