Re: jar file won't run
michau wrote:
Hi, I have a project in NetBeans, the project compiles, no errors, I
also included in it all required extra libraries:
javamail 1.4.1,
jaf (Java Activation Framework) 1.1.1
(except for the standard Java ones)
I have two main classes, that I can both run from NetBeans.
However if I use "Build Project" in NetBeans (which gives me a
ProjectName.jar file), I cannot run the jar file. There's an error
message after trying to run it:
"The jar file "ProjectName.jar" couldn't be launched. Check the
Console for possible error messages"
What type of project did you create in NetBeans? For NetBeans to create the
correct manifest, and to put the dependent jars where the application jar can
locate them, the project must be a Java Application. It also requires that the
project have a main class set in its properties.
If you do this then NetBeans should copy any dependent jars into the dist/lib
directory of the project. The manifest of the application jar should point to
the jars in the dist/lib directory, and so the application jar can be run
without any special command line arguments.
There is one exception to this, burried in the help:
"If you added a folder of classes or resources to the classpath (as opposed to
a JAR file or project), none of the classpath elements are copied to the dist
folder."
So if you added the javamail or jaf libraries as a folder rather than a jar then
the dist/lib directory may not have been created. Check under the project's
directory structure to see whether dist/lib has been created and populated with
the javamail and jaf jars.
Also if I try to use jar command from a terminal (on Mac OS) to create
a .jar file for one of the two main classes, like so:
"jar cf mainclass1.jar *.class"
it gives me the same error.
To build the application jar you need to tell the compiler where the dependent
jars are located (javamail and jaf). You do this using the -classpath argument.
Where can I finde the "console", what is it, can the solution to the
problem be there, or is it some other, perhaps trivial, issue?
The location of the console will depend on your desktop. There may not be one.
All it will show you is any error message generated by the command that
activating the jar from the desktop generated. You can do the same for youself
from a command shell. Change directory to the dist directory for the project
and run the command 'java -jar ProjectName.jar'.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555