Related link: https://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 https://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):
- 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
.
I did this: 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.
I dislike developing on Windows but at least there are pre-built libraries that are easy to install.
Related link: https://www.brunchboy.com/displaywatcher.shtml
One of my favorite features of Mac OS is how easily you can connect multiple displays, and spread your desktop between them. Heck, Microsoft even figured this one out after a decade or so. This means that when I’m at home, I like to have my PowerBook plugged into a nice big display, which has plenty of room to show the dock, while putting palettes like my DragThing window on the built-in display off to the side.
When I’m on the road, I have less real estate, so I like to hide the dock, and position a more compact DragThing configuration at the bottom of the screen, showing its own process dock.
Mac OS is very good about remembering the physical relationships between different displays that I connect, but I was still spending more time than I liked manually toggling the dock and switching between DragThing settings. So, being a typical proactively lazy geek, I decided to build a tool to do this for me. It would be a great excuse to learn a little Cocoa programming.
I’ve been using DisplayWatcher for a few months now, but I still get a little thrill out of watching the dock and DragThing reconfigure themselves, as if by magic, when I plug in or disconnect an external monitor. I also added the ability to run a script whenever my PowerBook wakes up from sleep–I use this to re-establish SSH tunnels for accessing and sending mail through my personal and corporate IMAP servers, CVS and the like. Now I’m far less reluctant to put my machine to sleep or move to other rooms, because there is no more hassle involved. That’s how a laptop should work!
Since DisplayWatcher seems very stable, I’m making it available for others who might find it useful. For now it is a binary-only download, but when I have time to write up some in-depth explanation, I hope to release it as open source as well. I certainly found it an instructive project myself, and would like to share that aspect as well.
If you’re interested, follow the URL associated with this posting and check out the instructions, or download it and play with it.
If you download and use it, please let me know… especially if you come up with interesting new scenarios!
Quick…what is the number one source of bugs?
My answer is “duplication”.
I finished off my basement a few years ago. I thought it would be cool to add a little high tech flash, so I put all of the basement lighting on X10. It was nice because I only had to run one wire to a bank of X10 dimmer switches that lets me adjust all the lights from a single spot. Cool.
Until a few months ago.
Now my lights turn on and off by themselves, and I don’t know how to diagnose the problem. I cannot think of any new electronic devices in my home…my assumption is that some signal is coming in from outside the house. It started with one particular light, then over the subsequent weeks the other lights in the basement started turning on and off by themselves. A light may switch on or off every 15-30 minutes now.
Maybe my house is haunted. Nah, that’s a stupid theory.
Do I need a Whole House Blocking Coupler? I’m reluctant to spend $75 and rip into my main breaker box based on a hunch. Is there any way to know what is causing this problem before I start buying new devices?
Even if you try to develop a total Java solution, you always need some kind of shell scripting. For standalone applications it is not convenient to let your users start an application by typing
java -Djava.util.logging.config.file=app.properties -cp path_to/lib.jar -jar app.jar
So in most cases these applications have shell scripts for starting and stopping the application. In some cases you’ll need few more scripts that works with your application.
Common tasks for startup script are:
- Setting local classpath for application
- Testing if required environment variables are set
- Executing java application
Why should you use groovy for this? and how?
First of all, Java developers find Java-like syntax scripting language easier to use, but huge advance is that you have access to all Java libraries that you need. For example you can establish XML-RPC or database connections if you have to.
I have the Java application that have XML-RPC interface and tends to crash from time to time because of unexpected signal 11 (more on this in some future post). I’ve created a groovy script that calls dummy XML-RPC method of the application and if an exception is thrown (meaning that application is not working properly) application is restarted. I’ve put this script in cron to be executed every five minutes and in case that application crashes it is restarted in few minutes. It’s needless to say that I’m sleeping much better since then :). Of course this could be done in million other ways, but the point here is that this is ten-lines script and ten minutes of work.
We can also go one step further. Most of these standalone application main methods do tasks like:
- Parsing command line arguments
- Reading property files
- Initializing and configuring other classes in order to run application (Loggers, scheduler, server threads, …)
This tasks could be also moved to startup scripts, leading to more maintainable application.
Command line argument parsing is the ideal job for scripting, because it’s all about string comparison.
Some of the basic configuration parameters could be set on the top of the script too. Of course you can’t avoid property files in general, because many libraries use them.
And if you have all the arguments and configuration parameters, you are free to initialize your object properly.
To make a shell script with groovy, all you need to do is to put
#!/usr/bin/env groovy
in the first line of the script, and you are back in Java-land.
Have you find any useful usage of groovy as a language for shell scripting?