[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: Help with jar export and external library

Paul Rubin wrote:
Eric Rizzo wrote:
B) Provide a mechanism by which the user can configure your app start-up to tell it where to find the libraries it needs.

Option A is generally preferred, because it reduces any headaches like you are experiencing. Option B relies on the user not only having the libraries but also being able to configure your app to point it in the right place. When going the option B route, you will almost certainly have to provide one or more script files (shell or batch) that can be tweaked to set the -classpath and -Djava.library.path appropriately. It is more work for the user and the developer, which is why I always choose option A whenever possible.


Therein lies the rub. I did a bit more research and discovered something I should have known in the first place: <argh>Java ignores the classpath when you're running a jar</argh>. I thought I could deploy with a batch file that would invoke my jar file using the -cp option, and the user would edit the batch file once to put in the correct path to the third-party jar. No joy. Unless I'm missing something, either I provide a batch file that gets the path to the library jar from the user, rewrites the manifest file to include that classpath, and repackages the jar to include the new manifest, or else I bail on the jar entirely and just send the user the class files (which is looking better and better).


I don't suppose anybody has found a better way to get around Java ignoring -cp when running a jar?

I was not aware of that side-effect of using java "-jar" but in any case you don't have to resort to deploying an exploded JAR (.class files). You can still ship a JAR and a batch file, just instead of using "java -jar ..." you include your JAR on the -cp arg to java.exe or javaw.exe. The -jar shorthand is just a convenience method, you can ignore it when it doesn't meet your needs.
An option that might make things simpler for your users is to use Ant to launch your app instead of a raw batch file. Ant is a nice scripting language and you can ship it with your app along with a tiny batch file to launch your Ant script.


A third option is to use one of the many Java application launching frameworks out there. In fact, Eclipse has its own - you edit eclipse.ini and/or pass arguments and eclipse.exe takes care of setting up the JVM env and launching the Eclipse app. There are other similar tools out there, too.

Hope this helps,
	Eric