16

I'm interested in any way that I can create an Ant task to checkout files from SubVersion. I "just" want to do the checkout from the command line. I've been using Eclipse with Ant and SubVersion for a while now, but my Ant and SubVersion knowledge is somewhat lacking as I relied on Eclipse to wire it all together.

I've been looking at SvnAnt as one solution, which is part of Subclipse from Tigris at http://subclipse.tigris.org/svnant/svn.html. It may work fine, but all I get are NoClassDefFoundErrors. To the more experienced this probably looks like a simple Ant configuration problem, but I don't know about that. I copied the svnant.jar and svnclientadapter.jar into my Ant lib directory. Then I tried to run the following:

<?xml version="1.0"?>

<project name="blah"> 

 <property environment="env"/>

 <path id="svnant.classpath">
  <pathelement location="${env.ANT_HOME}/lib"/>
  <fileset dir="${env.ANT_HOME}/lib/">
   <include name="svnant.jar"/>
  </fileset>
 </path>

 <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" /> 

 <target name="checkout">
  <svn username="abc" password="123">
   <checkout url="svn://blah/blah/trunk" destPath="workingcopy"/>
  </svn>
 </target>

</project>

To which I get the following response:

build.xml:17: java.lang.NoClassDefFoundError: org/tigris/subversion/javahl/SVNClientInterface

I am running SVN 1.7 and SvnAnt 1.3 on Windows XP 32-bit.

Thanks for any pointers!

Josh
  • 4,894
  • 6
  • 34
  • 42

7 Answers7

28

If you don't get SvnAnt working, you can always use exec:

<exec executable="/usr/local/bin/svn">
    <arg value="co" />
    <arg value="svn://repository/url" />
    <arg value="/destination/directory" />
</exec>
JW.
  • 50,691
  • 36
  • 115
  • 143
  • Perfect! Thanks! Not sure what the point of svnAnt is if you can just do this? – KOGI Jul 14 '11 at 22:42
  • 2
    In theory you want to avoid in ant tasks, since it's less cross-platform compatible. But that's not important in all cases. – JW. Jul 15 '11 at 00:55
  • 2
    It was the best solution in my case. Very simple (just install an svn client (Sliksvn in my case), make the PATH point to sliksvn/bin and that's all. svnant and javahl is a mess... – jmcollin92 Jun 24 '13 at 23:51
7

From that error it seems you probably need JavaHL jar on your classpath as well (JavaHL is Java language bindings for the Subversion API). You a

This URL might help: http://subclipse.tigris.org/wiki/JavaHL

Otherwise you can use use Ant to run a native command (but that would make it OS-dependant of course).

Wilhelm Kleu
  • 10,821
  • 4
  • 36
  • 48
5

Lets see if this helps for you, I copied svnjavahl.jar, svnClientAdapter.jar and svnant.jar into my $ANT_HOME/lib folder.

Then in xml file:

    <path id="svnant.classpath">
    <fileset dir="${ABSOLUTE-PATH-TO-ANT-HOME}/lib">
        <include name="**/*.jar"/>
    </fileset>
</path>

<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" /> 

And then, for checking out ..

    <svn dateFormatter="yyyy-MM-dd HH:mm">
    <checkout url="${MY-REPO-PATH}" 
              destpath="${checkout.dir}/MODULE-NAME" 
                      ....
</svn>

I think you are getting your error because you havent copied over svnjavahl.jar file into the lib folder. Do that and it should work.

Just noticed something, you are including ONE jar, not **/*.jar like I do, hence it cant find your svnjavahl.jar.

omermuhammed
  • 7,365
  • 4
  • 27
  • 40
3

If you are trying to get Ant to use the command line client, you may have to do the following:

<svn username="abc" password="123" javahl="false" svnkit="false"> 
Dingo
  • 3,305
  • 18
  • 14
  • 1
    If I don't set either the javahl or svnkit attributes then I get the NoClassDefFoundError. If I set one or both, to true or false, then I get "Cannot find javahl, svnkit nor command line svn client". I've tried all combinations, with and without svnjavahl.jar on the classpath. – Josh Mar 09 '10 at 11:45
  • If you do the following in your Ant file, does the PATH echoed contain the SVN binary directory? – user261840 Mar 09 '10 at 14:31
  • You need to either have a) native Java bindings working to subversion with JavaHL or b) a command line svn client available in your path. The suggestion in this answer works for b). – Jerry Brady Feb 23 '12 at 17:06
3
  1. All the .jar files in ANT_HOME/lib (and ${user.home}/.ant/lib and some other places) are automatically available, so your <typedef> doesn't need a classpath at all.

  2. The svnant distribution hasn't been updated for version 1.7. You can still use svnant.jar, but you need to replace these jars from svnant.1.3

    svnClientAdapter.jar
    svnjavahl.jar
    

    with updated versions. I extracted these from the subclipse 1.8 distribution, and didn't even have to rename them:

    org.tigris.subversion.clientadapter.javahl_1.7.2.jar
    org.tigris.subversion.clientadapter_1.8.0.jar
    
  • Indeed this helped me. If you are in 2012 and getting this error then it means that you are probably using subversion 1.7, which is not yet supported by svnant distribution. So just add the two libraries from above and it should work. – Sorin Postelnicu Dec 14 '12 at 17:28
  • 2014 and still no support for anything higher than 1.6 from SVNAnt. I guess they are using CLI themselves. – Maarten Bodewes May 20 '14 at 14:01
0

I found this page very helpful to get this going. For the latest version I found that the approved way of setting the svn settings is as follows:

<svnSetting svnkit="true" javahl="false" id="svn.settings" />

That means that the SVN command itself should be:

<svn refid="svn.settings">//Other commands</svn>

I actually wanted svnkit mode. The libraries mentioned above were OK, however I also needed the following added:

org.tmatesoft.sqljet_1.1.7.r1256_v20130327_2103.jar org.tmatesoft.svnkit_1.7.9.r9659_v20130411_2103.jar

org.tigris.subversion.clientadapter.svnkit_1.7.9.2.jar

These are all available in the subclipse download mentioned. The tmatesoft also needed:

antlr-3.5.2-complete.jar

Available from here: Antlr

PeterS
  • 2,818
  • 23
  • 36
0

I had almost the same setup, with the same issue.

I resolved it by deleting 2 svn*.jar's that I'd put in my ant install (on debian) under

/usr/share/ant/lib

earlier. Ant was confused by multiple jars.

nasty pasty
  • 6,584
  • 7
  • 24
  • 26