views:

724

answers:

5

On Ubuntu Linux with Gnome, running my Swing application by double clicking on the jar file in Gnomes file browser leads to errors because required libraries that are dynamically loaded via the Java Plugin Framework (residing in subdirectories) are not found.

The base libraries for the framework itself are resolved correctly, as stated in my executable jar's manifest file. However, once the framework launches, no plugins (not even the one specifying my platform) are found.

Launching the application from the terminal via

java -jar myjar.jar

works like a charm, ad does running the application by double-clicking a shell-script.

However, I'd like to avoid a terminal window. (I'm a Windows person, maybe it won't annoy linux people as it does annoy those on windows.)

The problem is reproducible across several Linux systems. Is there something I need to do so Java resolves the libraries correctly?

A: 

Java loads jars in order in its classpath, i.e. jar1:jar2:jar3... Most java applications ship with some sort of script which sets all of this up by specifying a classpath and a list of jars that the application will need.

What you want to do is probably not terribly advisable, as it means globally specifying a collection of jars that you want to load with every java application, and you're liable to create conflicts with whatever libraries ship with the application.

This isn't really a problem, the easiest solution is probably to throw together a little shell script launcher.

Steve B.
+2  A: 

I believe if you add to the jar a META-INF/MANIFEST.MF file containing a "Classpath:" attribute, with a value specifying the relative paths to the jars you need (I'm not sure whether they are space or comma separated), that might work.

David M. Karr
they are space separated.
dhiller
A: 

Either you can write a shell script to launch and that is what you invoke or create a launcher. Here is a quick "tutorial" on how to do it for several platforms.

http://java.sys-con.com/node/37130

Here is how Eclipse does it. Will probably give you some ideas:

http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/launcher.html

Good luck!

el_eduardo
A: 

As David suggested you can add the Class-Path manifest attribute in your jar for more jar manifest, Class-Path

shyam
+1  A: 

You may want to check: commons launcher. It will give you plain executable file that can be made to do all sorts of startup preparations (including setting classpath, etc). Most probably it is overkill for your problem, but you might try it (I would try it in your case just because I hate scripts).

jb