From the dot prompt in the directory that has all of the class files I am typing: jar -cvmf manifest.txt app.jar *.class. My manifest.txt file has one line: "Main-Class: BeatBoxGui".
It seems to package up fine and creates the app.jar file. However when I try to run the app.jar file, either from the dot prompt or by double clicking from Windows, I get an error. The windows error says: "Could not find the main class: BeatBoxGui. Program will exit." From the dot prompt the error message is: "Exception in thread 'main' java.lang.NoClassDefFoundError: BeatBoxGui <wrong name: beatboxgui/BeatBoxGui>
What am I doing wrong? Thanks for your help.
If you only have one line, it won't work. Manifest files need to end with a blank line. Lots more information in the Java™ Tutorials.
When you ask what is the fully qualified name of the BeatBoxGui class do you mean package.class? it is beatboxgui.BeatBoxGui. I changed the manifest file to read: Main-Class: beatboxgui.BeatBoxGui. And yes I have an extra line at the end of the manifest file. I am still getting the same error after creating the Jar file and trying to run it.
Create a new class with main(). Make sure it is in the same package as your current class with main(), and have it print "Hello World!" when run. Create a manifest file for it, and package it in a jar.
Open command window and run that class.
Post the file, the manifest, a screen print of the jar file from winzip or whatever, and the result. If it still doesn't work, that is.
Also, try to run your JAR file from the command line first, using "java -jar <jarfile>". When you double click a JAR file it's using the javaw tool which unfortunately shows the same error message (class not found or something like that) for any exception or error that is thrown from the main method. By using the command line you can see those exceptions / errors.
The manifest.txt file:
(extra line here below - space)
There is an attached jpg file that has a screenshot of the jar file in winzip. There is another of the command line screen showing the packaging and running of the jar file with the error messages.
Bud Tippins wrote:Yes, the BeatBoxGui.class file is inside a folder called beatboxgui. I'm not sure what you mean by "which is in the root of the JAR file" I have the Jar file in this same folder if that is what you mean.
Rob was asking if your jar file contains a directory called beatboxgui which contains a BeatBoxGui.class file. That's what he meant when he said 'the directory structure [of the jar file] must match the package structure'.
On your HelloWorld example: the name of that class is not Main, it is HelloWorldApp.Main. The manifest file must specify the fully-qualified class name of the main class to be run.
The jar file has a directory structure; the Main class in the jar file must be in the (jar file) directory HelloWorldApp. You cannot just put it in the "root" of the jar class.
I see that you are in a directory named HelloWorldApp when you try to run the program. That won't help, though since you're using a jar file, it won't hurt. One of the advantages of a jar file is that the jar file's directory structure is used to provide the right environment for fully-qualified path names, making it easier to run the program from anywhere on the disk. Default directories don't get involved in finding classes that way.
I'm afriad I do not have time to figure out exactly what to do in the jar command, but I expect you move up one level in your default directory (so that HelloWorldApp is a subdirectory), and then jar Main using a directory path. I think that will put Main in the jar file with the directory path intact, as you need it to be.
Bud Tippins wrote:From the dot prompt in the directory that has all of the class files I am typing: jar -cvmf manifest.txt app.jar *.class.
Change directory to the directory that contains your beatboxgui directory (i.e. up one level). Change *.class to beatboxgui.
jar -cvmf manifest.txt app.jar beatboxgui
You'll also need to move your manifest.txt up a directory