Building Subversion With Java Bindings On Mac OS X
![Brian M. Coyner](https://imageproxy.pixnet.cc/imgproxy?url=https://www.macdevcenter.com/images/people/brian_coyner.jpg&width=65&height=85)
Brian M. Coyner
Jul. 17, 2004 12:28 PM
Permalink
URL: 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:
- Build and install a stable release version (currently 1.0.5) of the client
- 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
Step 2
Execute autogen.sh
./autogen.sh
Step 3
Execute configure
./configure \
--enable-javahl
--with-jikes=no
--prefix=/usr/local/svn-trunk-10351
--enable-javahl
--with-jikes=no
--prefix=/usr/local/svn-trunk-10351
Step 4
Execute make
Step 5
Execute make javahl
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):
- svnjavahl-1
- libsvnjavahl-1 (Mac OS X naming convention)
- 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
.
cp libsvnjavahl-1.jnilib /usr/lib/java
You should now be able to:
- use Subversion from the command line
- write Java code to communicate with Subversion
I hope this helps.
Brian M. Coyner is coauthor of the Java Extreme Programming Cookbook and a Senior Software Engineer with Object Computing, Inc. in St. Louis, Missouri.