[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:
Hi all,

I have a Java project that requires third-party software supplied as a jar file (installed at location /A/their.jar on my box) and a native library (DLLs at location /B/ on my box). I put the jar file at A on the build path as an external jar (location B is on my system command path) and the project compiles and runs fine from inside Eclipse. The problem comes when I export a jar file and try to run it outside Eclipse.

Running the jar generated from this set up causes NoClassDefFound errors as soon as it needs something from the external library, even though /A/their.jar is on my system classpath, and regardless of whether I specify it via -classpath (or -cp) in the invocation. Note that if I unpack the jar archive and run the main class file directly, it runs fine.

After assorted failed efforts (and considerable swearing) I changed my build path to show /A/their.jar as part of a user library, rather than just an external jar. When I export my app as a jar and run it, using the -Xbootclasspath/a: option to add /A/their.jar to the boot path, it finds the bleeping classes -- but I get an error message because it can't find the native libraries in /B (again, regardless of whether I specify it through -Djava.library.path, put it on my system command path, fire flares from it's home directory, ...).

So what's the secret handshake? The user will have /A/their.jar and some version of /B (which is platform dependent) installed, but not at /A and /B respectively, so I need a way for the user to specify those paths and get the bleeping jar file to run. Having the user unpack the jar and run the main .class file is an option, but not an attractive one.

The only way to get external-dependencies to work is to either:
A) deploy with your app everything it needs, including third-party libraries
or
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.

Unpacking the library JAR should make no difference, so I suspect some subtle problem in the script to launch your app. You could post the exact script or command you're using to see if anyone spots the problem...

Hope this helps,
	Eric