The only pure Java Subversion library in the world!
Home Get Library Knowledge Base Licensing

Using JavaSVN with Ant

There are two ways of using JavaSVN in Ant tasks. First way is using svnant - part of Subclipce project, how to do it you may read this documentation page for details. Another way, that is described below, is using JavaSVN command line interface.

Sample Ant tasks that uses JavaSVN (contributed by William Lovins)

Note: There are areas where this library is very inefficient when working with large repositories which will be resolved in later versions.

Note: The easiest way to use this command is to treat the commands passed to the library the same way that you would the normal svn binary. There is no svn task at this time as there is in the svnant library. This too will be resolved in a later version.

The main advantage to this library is that neither subversion nor any associated libraries need to be installed on the server.
Additionally, this documentation will be expanded and improved on later versions. This initial page is being made available for people who would like to either test this library or who would like to help improve it (e.g. - writing a proper <svn> task set or fixing bugs).

Parameters

Please see the svn documentation for assistance on what parameters the command accepts. A large subset of the command line arguments are available via the javasvn-cli.jar file, including lesser used switches such as "svn status -u".

Examples

Checking out files from the repository

If you need to do an initial checkout, this target will checkout files from http://sources.example.com/TESTING to the local directory /usr/src/TESTREPO. The username and password arguments can be omitted if you have anonymous checkouts from your repository.

  <target name="svnCheckout">
    <property name="source-root" value="/usr/src"/>
    <property name="repository.URL" value="http://sources.example.com"/>
    <java classname="org.tmatesoft.svn.cli.SVN"
       dir="${source-root}/TESTREPO" fork="true">
      <arg value="co"/>
      <arg value="--username"/>
      <arg value="admin"/>
      <arg value="--password"/>
      <arg value="admin"/>
      <arg value="${repository.URL}/TESTING"/>
      <classpath>
        <pathelement location="${antroot}/LIB/javasvn.jar" />
        <pathelement location="${antroot}/LIB/javasvn-cli.jar" />
      </classpath>
    </java>
  </target>

Commiting files to the repository

If you had an existing local copy of a repository that you want to check files into, you could use the following target to commit the files. The "-m" argument of "Testing" is set differently than the other arguments. Please use a single quote "  '   " to surround the double-quoted message, as shown in the example below.

This example would commit all changed files from the local directory /usr/src/TESTREPO to the repository located at http://sources.example.com/TESTING the same way that the command line version would.

  <target name="svnCommit">
    <property name="source-root" value="/usr/src"/>
    <property name="repository.URL" value="http://sources.example.com"/>
    <java classname="org.tmatesoft.svn.cli.SVN"
      dir="${source-root}/TESTREPO" fork="true">
      <arg value="commit"/>
      <arg value="--username"/>
      <arg value="admin"/>
      <arg value="--password"/>
      <arg value="admin"/>
      <arg value="-m"/> 
      <arg value='"Testing"'/>
      <arg value="${repository.URL}/TESTING"/>
      <classpath>
        <pathelement location="${antroot}/LIB/javasvn.jar" />
        <pathelement location="${antroot}/LIB/javasvn-cli.jar" />
      </classpath>
    </java>
  </target>


If you have any questions regarding JavaSVN, would like to report a bug or contribute a patch, please write to support@tmatesoft.com