How to checkout from SVN with an ANT task?

64,038

Solution 1

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>

Solution 2

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).

Solution 3

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.

Solution 4

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"> 

Solution 5

  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
    
Share:
64,038
Josh
Author by

Josh

Updated on November 20, 2020

Comments

  • Josh
    Josh over 3 years

    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
    Josh about 14 years
    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.
  • user261840
    user261840 about 14 years
    If you do the following in your Ant file, does the PATH echoed contain the SVN binary directory? <property environment="env"/> <echo message="PATH = ${env.PATH}"/>
  • KOGI
    KOGI almost 13 years
    Perfect! Thanks! Not sure what the point of svnAnt is if you can just do this?
  • JW.
    JW. almost 13 years
    In theory you want to avoid <exec> in ant tasks, since it's less cross-platform compatible. But that's not important in all cases.
  • Jerry Brady
    Jerry Brady about 12 years
    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).
  • Sorin Postelnicu
    Sorin Postelnicu over 11 years
    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.
  • jmcollin92
    jmcollin92 almost 11 years
    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...
  • Maarten Bodewes
    Maarten Bodewes almost 10 years
    2014 and still no support for anything higher than 1.6 from SVNAnt. I guess they are using CLI themselves.