• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

packaging up Swing application into Jar file for distribution

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to package up my first swing application into a Jar file for distribution. I created it in NetBeans.

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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the fully-qualified name of the BeatBoxGui class? Is it the same as you wrote in the manifest file?
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.
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell, Thanks for your help.

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.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I think we've run to the end of what we can do with what you tell us happens. It's time to show us some source.

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.

rc
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the BeatBoxGui.class file inside a folder called beatboxgui which is in the root of the JAR file? Because the directory structure must match the package structure.

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.
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ralph, thanks for your help. O.k. I've created a hello world app and packaged it. I am still getting errors when I try to run the packaged jar file. Here is the source code and manifest file:



The manifest.txt file:
Main-Class: Main
(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.

java-jar-screenshot.JPG
[Thumbnail for java-jar-screenshot.JPG]
screenshot of dot prompt showing packaging and running of jar file
jar-file-in-winzip.JPG
[Thumbnail for jar-file-in-winzip.JPG]
screenshot of the jar file in winzip
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob, Thanks for your help. 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. I'm running the jar file first from the command prompt and getting errors there as well.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try renaming the file to manifest.mf and then try to jar it.
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maneesh, I did that and it still gives the same error.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you wrote Main, shouldn't you have used the fully-qualified name of the class?
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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'.
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joanne, Thanks for your help. I don't believe that it does. I've attached a screenshot of the file. How do I go about creating that directory and putting BeatBoxGui.class file in that directory of the jar file? (I've since renamed this to BeatBoxSaveOnly).
BeatBoxSaveOnly-jar-file-screenshot.JPG
[Thumbnail for BeatBoxSaveOnly-jar-file-screenshot.JPG]
screenshot of jar file
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid I cannot be complete in this answer; I'm at work and have to get back to it.

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.

rc
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for all of your help. I finally got it working!
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic