[Java-gnome-developer] (Hacked) version of 4.0.13 in Maven repo
Brought to you by:
afcowie
|
From: Jacek F. <ja...@gm...> - 2009-11-13 18:04:18
|
I wanted to try to deploy Java-GNOME 4.0.13 in a Maven repo, so that it could be easily used in Maven-based projects. It turned out to be far more complicated than I thought, due to the native library issues. In particular, the way Plumbing.loadNativeCode() works on startup. It works well when Java-GNOME is installed a system lib, but not well when it's a Maven lib in a local Maven repository. I found this interesting blog entry on how to Mavenize JARs with embedded JNI libraries in them: http://docs.codehaus.org/display/MAVENUSER/Projects+With+JNI I added the dependency on the utility mentioned in this entry and modified loadNativeCode() to attempt loading the .so directly from the jar's META-INF/lib (which is how I deploy it in the Maven repo). //attempt to load from JAR try { NativeLoader.loadLibrary("gtkjni-" + getVersion()); return; } catch (Throwable ex) { System.out.println("Failed to load from JAR: " + ex.getMessage()); //ignore } It works perfectly, but it is unfortunately a fork of the current logic. However, this makes it very easy to use in maven projects, just add this to your pom.xml: My Maven repo: <repositories> <repository> <id>javabuilders</id> <url>http://javabuilders.googlecode.com/svn/repo</url> </repository> </repositories> The Java-GNOME dependency: <dependencies> <dependency> <groupId>org.gnome</groupId> <artifactId>java-gnome-linux-x86</artifactId> <version>4.0.13</version> </dependency> </dependencies> That's all. Now you can just create Java-GNOME on Linux x86 apps and since the .so is embedded directly in the JAR itself it loads transparently. The Maven project I use to deploy it is in my github repo: http://github.com/jacek99/java-gnome-maven Obviously, this is an experiment, but it seems to work very well and makes it easy to create Java-GNOME apps by removing the complications related to the native shared library. Theoretically, we could even embed copies of it for all platforms (sort of a fat binary) and then intelligently load the one we need based on the current platform. I look forward to any feedback from the community: love it, hate it, etc. Cheers, Jacek |