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
First, thanks for the information and code.

I have been using Ant to deploy my applications into Staging and Production environments (adjust coldspring settings, exlude certain files, ftp, etc...) I recently decided to go forward and try using SVNAnt and I am running into an error that has been a pain to solve. After following the steps you provided I try to run the build and recieve the following error in my build.log file:

BUILD FAILED

D:\Source\library\build.xml:62: Cannot use javahl nor command line svn client
   at org.tigris.subversion.svnant.SvnTask.execute(Unknown Source)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
   at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
   at org.apache.tools.ant.Task.perform(Task.java:348)
   at org.apache.tools.ant.Target.execute(Target.java:357)
   at org.apache.tools.ant.Target.performTasks(Target.java:385)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

Any help in resolving this issue would greatly be appreciated. Thanks again
# Posted By Paul | 6/19/08 3:59 PM
For people running windows and getting the "Cannot use javahl nor command line svn client" message, it's because you need the requisite javahl dll's referenced under the windows PATH environment variable.

I added the org.tigris.subversion.javahl eclipse plugin directory under my my PATH variable, restarted Eclipse and it started working.
# Posted By James Netherton | 7/10/08 9:06 AM
@alex

I too was getting the error "Could not load definitions from resource svntask.properties. It could not be found."

I finally found a solution on http://www.infoaccelerator.net/blog/post.cfm/svn-a... Change the taskdef to:
<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" />
# Posted By Richard Davies | 7/23/08 3:44 PM
Another go at the Captcha - this time just long enough to say 'Please excuse spelling errors in the previous comment
thanks for understanding
# Posted By Atlanta Houses | 1/10/09 4:30 AM
thanks for your post. i have also used ANT is really good.
# Posted By Atlanta foreclosures | 2/3/09 9:32 AM
thanks for your post I speeck on my blog http://www.telavenir.com
# Posted By Anonymous | 3/3/09 3:39 PM
Thanks for sharing this info, it will be very usefull for my website.
# Posted By betclic | 3/12/09 6:50 AM
thanks for your works
# Posted By Miami Houses, Atlanta houses | 3/25/09 2:29 AM
Thx so much !! you help me :)
# Posted By Bwin | 3/31/09 5:32 AM
thanks for your great post
# Posted By Atlanta Homes | 4/6/09 2:14 AM
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 Atlanta Discounted houses | 4/13/09 1:29 AM
Thank you to provide me invaluable information for my Web site
# Posted By Betclic | 5/5/09 10:01 PM
Thks for info.
# Posted By Freerolls | 5/11/09 8:39 AM
Very interesting!
# Posted By Unibet | 5/11/09 8:47 AM
thanks for your post. i have also used ANT is really good. <a href="http://www.citazioni-celebri.com">frasi</a>
# Posted By dan | 5/12/09 10:03 PM
Very nice article thanks you for sharing
# Posted By unibet | 5/13/09 6:49 AM
So usefull. thanls a lot or sharing...
# Posted By Bwin | 5/16/09 8:32 PM
Thanks !
# Posted By Betway | 5/19/09 5:54 PM
Thanks for sharing.

http://www.dollarsblog.com
# Posted By George | 5/24/09 11:27 AM
# Posted By Giants fan | 5/24/09 11:30 AM
Great article, thanks !
# Posted By Betclic | 6/1/09 6:42 AM
thanks
# Posted By Atlanta Foreclosures | 6/6/09 7:56 AM
Very interesting ! I'll be sure to check it out.
Thanks for your post. I have also used ANT is really good.
In French http://www.voyance-officielle.fr
# Posted By voyance | 6/17/09 8:40 AM
so usefull for me thanks...
# Posted By betclick | 6/29/09 9:37 PM
It's really a very good job! There is a version here http://www.alphamedium.fr
# Posted By Eric | 6/30/09 7:15 AM
Thanks for the idea, ANT Builds for file storage, but I do not have the jar files, help me to create and send the settings on my mail.

Welcome to the site http://www.queentorrent.com
Here you can download a good movie
# Posted By Katty Lee | 7/12/09 3:08 PM
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).
# Posted By club penguin cheats | 7/13/09 6:51 PM
Great post!
Thanks you very much for sharing it
# Posted By betclic | 8/5/09 8:35 AM
Excellent work, I never tire of reading your articles. I also spoke to my site
http://www.chat-rencontre-libertine.com
# Posted By adresse msn coquine | 8/11/09 2:15 AM
I found your article very interessant.Merci for your partage.J 'ave personally tested ANT it's very good. <a href="http://www.top-horoscope.com">horoscope</a>.
# Posted By horoscope gratuit | 8/13/09 9:04 AM
thanks for this topic
# Posted By ??????? | 8/20/09 1:50 AM
thanks for sharing such a nice information with us.
# Posted By SEO Sevices | 8/26/09 10:34 PM
really good information. we will try the same.

thanks.
# Posted By SEO Services | 8/26/09 10:36 PM
i also hope to use the information in future.
http://www.rankingbyseo.com
# Posted By SEO India | 8/26/09 10:39 PM
hmmm good one really. thanks for information.
http://www.flexsin.com
# Posted By Admin | 8/26/09 10:42 PM
i have a blog but trying to build a website soon where i will try the same.
http://link-popularity-india.blogspot.com
# Posted By Link Building Services | 8/26/09 10:44 PM
Nice Post
# Posted By seo company | 9/2/09 4:09 AM
Nice Post
# Posted By seo company | 9/2/09 11:31 PM
thaaaaanx very nice :)
# Posted By ????? ?? ?????? | 9/11/09 4:51 AM
# Posted By z3lanh.com | 9/14/09 11:39 PM
Thanks for nice info about the code snippet.
# Posted By Araba | 9/29/09 7:23 PM
Websites are always helpful in one way or the other, anyways, <a href="http://www.ccnaguide.com">ccna</a> a good way to get started to renovate your dreams into the world of reality.
Thanks
Micheal,
# Posted By micheal.smith898 | 10/3/09 12:14 AM
I tried running it on my vista box, but I got the error "Cannot use javahl nor command line svn client". I'll see if I can work around it <a href="http://www.best-online-degree-programs.com/earn-de...">earn degree online</a>
# Posted By gina edrapa | 10/10/09 9:28 PM
For Link Building Services India, Link Popularity Services, Link Popularity Building, <a href="http://www.profitbysearch.com/link-building-servic...">Link Building India</a>, Visit Profit By Search
# Posted By peter | 10/14/09 12:47 AM
Your post is very interesting and informative, thanks!
# Posted By Bwin.fr | 10/19/09 3:53 PM
thanks for this topic <a href="http://www.telavenir.com">voyance telephone</a>
# Posted By francois | 10/29/09 7:49 AM
Seocorporation is a raising company that aims to provide the high quality services to the customer in the field of SEO, Targeted Link Building and many more at most affordable prices.
# Posted By honey | 10/29/09 12:57 PM
seocorporation is a Professional SEO Company in India, offering website optimization & link building services for Google, yahoo and MSN.
http://seocorporation.wordpress.com/
# Posted By seocorporation | 10/29/09 1:00 PM
# Posted By mohamad | 10/31/09 5:21 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.003. Powered by ColdFusion Server v8,0,1,195765.