Building Subversion With Java Bindings On Mac OS X

by Brian M. Coyner

Related link: http://subversion.tigris.org




Building Subversion on Mac OS X is
not hard. Building the Java bindings for
Subversion is challenging until you know what to do. Hopefully you find this
information helpful.




This blog shows how to build Subversion and the Subversion Java bindings. Why?
There are a few reasons you may need the Java bindings:



  • You want to write Java code to communicate with Subversion

  • You want to use SvnUp, which
    can be installed as a plug-in to
    IDEA



Install Subversion




Before we get started you need to install a
Berkeley DB
.
I have version 4.2 installed. They have plenty of documentation to help you.



Step 1


As of today, this is a two step process:



  1. Build and install a stable release version (currently 1.0.5) of the client

  2. Use the stable release version to checkout the latest source
    from the repository


NOTE: In order to build the Java bindings we need the latest source. Version 1.0.5
does not appear to support building the Java bindings using --enable-javahl and
SWIG does not work.



NOTE: Once version 1.1 becomes stable you should be able
to build the Java bindings using that code base, thus checking out
the latest code is no longer necessary.



NOTE: I was unable to build the Java bindings using
Subversion 1.1 RC1, thus having to build against the HEAD of the
repository. You may have better luck.





Once you have the stable release of Subversion installed use it to download the
latest version Subversion source code from the repository:



svn co http://svn.collab.net/repos/svn/trunk subversion-tip


Now change to the source directory


  cd subversion-tip


NOTES

The Subversion revision number in this example is 10351.



Step 2


Execute autogen.sh


  ./autogen.sh



Step 3


Execute configure



./configure \
--enable-javahl
--with-jikes=no
--prefix=/usr/local/svn-trunk-10351


NOTES

--enable-javahl

Enable compilation of Java bindings. This option appears to only be
available on version 1.1 and higher. I tried and tried to get version 1.0.5
to build using SWIG. I gave up on SWIG when I found out from
Weiqi
that the latest version supports javahl.



--with-jikes=no

For some reason Jikes is the default compiler. If Jikes is used the
configure script does not appear smart enough (on Mac OS X) to build the
classpath needed to compile the Java bindings. Disabling Jikes "enables" the
javac compiler, which works without any problems.




--prefix=/usr/local/svn-trunk-10351

You can put the compiled libraries where you want. I like to keep them
bundled in their own directory.



Step 4


Execute make


Step 5


Execute make javahl



NOTES

You may receive an error really quick. If the error has anything to do
with the /subversion/bindings/javahl/classes directory
not being found then manually create
the directory. Specifically, the classes directory does not exist.


Step 6


Execute make install



Subversion should be installed at /usr/local/svn-trunk-10351.

Step 7


Execute make install-javahl



The Java Bindings API should be installed at
/usr/local/svn-trunk-10351/lib/svn-javahl/svn-javahl.jar





Using The Java Bindings API


We have successfully built Subversion and the bindings
(svn-javahl.jar)
necessary for us to write Java code to talk with Subversion. Let's take a
look at how we can get started using the API.



Here's a class that uses the svn-javahl API:



import org.tigris.subversion.javahl.SVNClient;
import org.tigris.subversion.javahl.Notify;
import org.tigris.subversion.javahl.Revision;

public class SubversionDemo {

public static void main(String[] args) throws Exception {

SVNClient client = new SVNClient();

// The SVNClient needs an implementation of Notify before
// successfully executing any other methods.
client.notification(new Notify() {
public void onNotify(String path, int action, int kind,
String mimeType, int contentState, int propState,
long revision) {
System.out.println("SubversionDemo.onNotify");
}
});


// Assume that there is a valid repository with a project called
// 'freedom'.
client.checkout("file:///Users/briancoyner/svn-repository/freedom",
"/Users/briancoyner/MyProjects", Revision.HEAD, true);
}
}


NOTE: Be sure to add the svn-javahl.jar file to
your classpath.




After running this you should see this error message:



Exception in thread "main" java.lang.UnsatisfiedLinkError: no svnjavahl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1491)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at org.tigris.subversion.javahl.SVNClient.(SVNClient.java:48)
at com.briancoyner.subby.SubversionDemo.main(SubversionDemo.java:13)



The SVNClient object tries to load one of these native libraries
using System.loadLibrary (in this order):


  1. svnjavahl-1

  2. libsvnjavahl-1 (Mac OS X naming convention)

  3. svnjavahl




The "actual" native library on Mac OS X is called libsvnjavahl-1.0.dylib,
located under /usr/local/svn-trunk-10351/lib.

Mac OS X loads libraries
that start with lib and end with .jnilib.
A symbolic link named libsvnjavahl-1.jnilib already exists pointing to
libsvnjavahl-1.0.dylib, so we can simply
copy the link to a location known by the System property java.library.path.



I did this: cp libsvnjavahl-1.jnilib /usr/lib/java


You should now be able to:


  1. use Subversion from the command line

  2. write Java code to communicate with Subversion


I hope this helps.






I dislike developing on Windows but at least there are pre-built libraries that are easy to install.


2 Comments

MPorter
2004-07-19 09:15:19
Pre-Built Packages For Mac OS X
For those who don't want to go through building the subversion client for Mac OS X, we have had packages on our website since early June. Also, there is a package for the IntelliJ plugin.


http://metissian.com/projects/macosx/subversion/http://metissian.com/projects/macosx/subversion/



Cheers,
matthew

MPorter
2004-07-19 09:22:32
URL Mangled
The correct URL is:


http://metissian.com/projects/macosx/subversion