You are not logged in.
Dear Java gurus,
Imagine I have a Java application. I wish to bundle it all within a jar file. The problem is, I also wish to add some dependencies, in the shape of a couple of other jars. This means that the user could run the app using the straight-forward "java -jar myapp.jar" command.
So, I jar it all up. This Jar contains a MANIFEST.MF that specifies the main class, and also the classpath. ("Class-Path: lib/other.jar") as the extra jars were in a dir called lib within the jar.
But, this doesn't work run as java complains about not being able to resolve classes that exist within other.jar.
I have yet to find anything on the net beyond really basic examples of using jar. Anyone had more experience with it and can share some tips?
Offline
Its a horrible thing. Basically, you can't include jars in jars. I asked this question on the Java.sun.com forums a while ago if you want to search there. Its a common question and pisses people off.
You have some other options:
1: extract all dependency jars and include the classes in a single jar file.
2: distribute multiple jars and set the Class-Path in the Manifest to point to them. Since you're pointing at lib/other.jar, you gotta use:
myjar.jar
lib/other.jar
You won't find another way around this. I recall somebody suggesting that packaging jars with jars should be available in mustang, but as of yet, it is not so.
Also, I would strongly recommend starting to use Java Webstart /JNLP for distributing java apps. I've never done it, but it takes all this hassle out for you by automatically maintaining dependencies. I'm intending to try to get Ensmer going using JNLP sometime.
Dusty
Offline
Doesn't matter. I've finally found from Sun's website a nugget which says that it can't be done from the Manifest. You need to bootstrap with a start-up class which uses ClassLoaders to loadup all the necessary classes within the jar.
Found One-Jar which looks like it will do the job.
Offline
Also, I would strongly recommend starting to use Java Webstart /JNLP for distributing java apps. I've never done it, but it takes all this hassle out for you by automatically maintaining dependencies. I'm intending to try to get Ensmer going using JNLP sometime.
Dusty
I've had a little experience with WebStart. It's quite nice. Maybe I'll tinker with that then.
Offline
Hmm... never saw that option, looks kind of inelegant to me, but I guess it would work. I still suggest JNLP. ;-)
Dusty
Offline
I use fatjar to do the same thing - it's an eclipse plugin that can bundle jars together.
Offline