dcsimg
How can I include a 3rd-party jar in a java app?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ralph_Cook
Posted On:   Sunday, March 16, 2008 01:49 PM

I have written a java app that I would like to put on multiple machines easily. It depends on a 3rd-party java library with its own jar; I would like some (easy) way to say "Here is the jar with my app, and here is a jar it depends on, doubleclick on my jar (in Windows, if that matters) and it runs and gets what it needs from this other jar." I've seen references implying that the manifest file in my jar can specify other jars, but I don't see an option in Eclipse to create that dependency -- in fact, the Eclipse jar packager appears to go out of its way to make sure that a 3rd-party jar I have in my project does not appear in the list of things I can export to my own jar. I suppose I can distribute the jars sepa   More>>

I have written a java app that I would like to put on multiple machines easily. It depends on a 3rd-party java library with its own jar; I would like some (easy) way to say "Here is the jar with my app, and here is a jar it depends on, doubleclick on my jar (in Windows, if that matters) and it runs and gets what it needs from this other jar."


I've seen references implying that the manifest file in my jar can specify other jars, but I don't see an option in Eclipse to create that dependency -- in fact, the Eclipse jar packager appears to go out of its way to make sure that a 3rd-party jar I have in my project does not appear in the list of things I can export to my own jar.


I suppose I can distribute the jars separately if I have to -- the 3rd-party is open source, so I can hand out a copy without problems -- but how do I get my code to use it on an arbitrary machine? I sure hope I don't have to hard-code its path anywhere...


rc

   <<Less

Re: How can I include a 3rd-party jar in a java app?

Posted By:   Ralph_Cook  
Posted On:   Sunday, March 16, 2008 02:15 PM

Ok, more information. The java mechanism for this is to put the jar file in the "Class-path:" line in the MANIFEST.MF; this file needs to be in the META-INF directory, which needs to be in the root directory of the jar file. Then you put the jar file you've referenced into the same directory as the jar containing this manifest, and the app can find the jar file.


So I still have the eclipse question -- how do I get this done? The jar packager does not seem to have any options for it; I tried creating a manifest right under the project, but I end up with that one and another one and the result doesn't work. Do I need to create a META-INF directory and hand-edit the manifest in that, and tell eclipse not to bother when it finds it exists already? Seems kinda "manual labor" compared to eclipse's other features.


So at least I know how to get it done with the Java runtime, I would still like to know how (or whether) eclipse has some support for this. I'd rather not have eclipse generate the jar, unpack the jar, edit the manifest, and then repack the jar each time I do this.

About | Sitemap | Contact