Re: Jar execution problems
On 17/09/10 14:09, Hakan wrote:
When trying to run an application built in Netbeans which makes use of
an external library, I can't get it to work on my Linux server. It gives
me a NoClassDefFoundError where it can't find the class in the external
jar file. When I want to add this file to the classpath, it gives me bad
magic number invalid file error message so please help me if you know
what I should do.
Regards,
H?kan Lane
If you run a jar using -jar then you cannot modify the classpath on the
java command-line. The jar determines the classpath via its manifest.
The manifest in the jar should be created by Netbeans (provided you
created the correct Java application type in Netbeans). When Netbeans
creates your application it does so in a directory called dist in the
project directory. This contains the application jar, and any other
necessary jars are copied into the lib directory within dist. The
manifest classpath in the application jar will point to the jars in the
lib directory. If you want to relocate the application jar you must also
relocate the lib directory, and its contents, to the same location as
the application jar.
For example, I have an application called Administration (which handles
certain admin tasks), contained in the jar Application.jar. It requires
the additional jars mail.jar and swing-layout-1.0.3.jar. The contents of
the packaged dist directory are:
Administration.jar
lib/swing-layout-1.0.3.jar
lib/mail.jar
to relocate the application somewhere else I need to replicate the
directory structure in dist. So I'd need to copy the Administration.jar,
and the entire contents of lib, to the new location.
--
Nigel Wade