• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Main Class Not Found in JAR file

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I'm attempting to export a JAR file from a package in my Eclipse 3.1 workspace (Windows XP) that contains a class with my main method and for some reason, at runtime I receive an error from the JVM that it cannot find my main class. The class was assigned in the JAR wizard, it is listed in my manifest file, and I've even tried to generate the JAR file from the command line with the same result despite seeing that the main class file was compressed and added to the jar.

Can someone point me in the right direction to correct this? I'm currently running JRE1.5.0_05. Thanks for your help!

Chris Simpkins
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By jar wizard do you mean the FatJar plugin? I have had no problems with small programs using that.
 
Chris Simpkins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, sorry, I meant the wizard in Eclipse that allows you to export JAR files. It allows you to select the main class.

For some reason, the class is not being found in the JAR file.

-CS
 
Rancher
Posts: 5114
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you open your jar file with WinZip and look at its contents? Look at the contents of the manifest file. Is there a correct Main-Class: entry?
Do the jar entries have the correct path for the packages they are in?
Copy and paste results here if further questions.
 
Chris Simpkins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your message. So, I took your advice and examined the directory structure in the JAR file with WinZIP. When it is packaged as a JAR, there are three main directories in the JAR file. One is called .settings and contains resources, ui, and core prefs classes that come from eclipse packages. Another folder is called META-INF and contains the manifest file which has been named MANIFEST.MF. The final one is an appropriate directory tree of my classes:

org/pongpong/pong

This directory contains all of the classes that I've coded, including the class that contains my method which is named StartPong.class.

Does the manifest file need to come out of this separate directory so that the virtual machine can determine the appropriate directory path to find the classes?

Also, in looking at this, another question has come up. I've used a number of classes from open source code that were in separate packages in my workspace in the Eclipse IDE. None of the classes from these packages are contained within my JAR. For instance, I am using the httpclient class from apache which is in the package: org.apache.commons.httpclient. This is on my classpath in the IDE and compiles and runs without any problems when I run it from within the IDE; however, will there be problems without these classes in the JAR file at runtime or are the references to the classes compiled into my class files? If the former is true, can you tell me how to do this either in eclipse or using the command line approach. I've made JAR files in eclipse 3.0 without any problems and since I upgraded to 3.1 I've run into this issue. I suspect that some of my settings are wrong.

Any help would be greatly appreciated!

-Chris
 
Chris Simpkins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry didn't answer your question about the Main class entry on the manifest file. It does have a correct path to the main class.
-CS
 
Norm Radder
Rancher
Posts: 5114
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, need more info.
Could you try to execute your jar file with java.exe and copy the full console here. Also post the contents of your manifest file.
 
Norm Radder
Rancher
Posts: 5114
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also does the class specified in the manifest Main-Class: entry have a correct main() method?
 
Chris Simpkins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again for your help Norm. Here is all of the information that you requested:

Manifest file (includes a return after the final line):


The main class (StartPong):


The console output when I try to run the JAR file from the command line:



It appears that despite importing the appropriate l&f package which is on my classpath and recognized by the IDE, the classes are not being packed into the JAR. This gets back to my second question from my post above regarding the remainder of open source packages that I am using in this project. Eclipse recognized all of the imports after I added them to the classpath, but I think that I am going to have the same problem with other package imports as well because when I search through the classes in the JAR file, the only classes that are there are the ones that are included in my package (org.pongpong.pong).

Any thoughts?

Thanks again,
-Chris
[ September 25, 2005: Message edited by: Chris Simpkins ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I suggest you take a look at the FatJar plugin - it does all this stuff for you.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the -jar option, Java ignores the global classpath variable. You need to modify your manifest file to include a "Classpath:" (or is it "ClassPath:"?) attribute that indicates where the third-party jar files are located.

Layne
 
Chris Simpkins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for pointing out the FatJar plugin Barry. I'll definitely check it out.

I'm still interested in learning more about these classpath, jar packaging issues. I've read a number of resources both on the web and in print and in my experience this information hasn't been very well documented. Perhaps I haven't looked in the right places I'll post a message to let you know how the FatJar plugin worked.

Layne, do you mean something like this?


My eclipse workspace is where I have all of the JAR's and this is the path to that directory. Can you list multiple directories if the imported packages are in different locations or do they all have to be in the same directory?

Thanks for all of your feedback. This has been extremely helpful.

-Chris

[ September 25, 2005: Message edited by: Chris Simpkins ]

[ September 25, 2005: Message edited by: Chris Simpkins ]
[ September 25, 2005: Message edited by: Chris Simpkins ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have experienced a similar problem after changing to 3.1, but I updated my WinXP environment variables to include CLASSPATH. I have this variable setup to point to .;..; and the location of the lib folder I am using. This I've done this I've not had any of the similar problems you have been having.

Hopes this helps some.
 
Chris Simpkins
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out what was causing the problem. One of the JAR files (substance look and feel) that my application used was being included in the main directory of my application's JAR without the path structure that was being used for the import. I downloaded the substance L&F JAR as compiled files and placed the JAR on the buildpath for my own classes. Interestingly, this worked when run from within Eclipse, but obviously, previously compiled files are not re-compiled and the substance L&F JAR was inaccessible in the location where it was placed in my JAR.

My solution was to download the source files and include them in a separate project in my workspace. I then listed this as one of the dependent projects on my buildpath and voila... it worked. Proper file structure and a JAR of Pong!

Thanks to all who helped. If anyone runs into a similar problem and needs any help, feel free to e-mail. The Eclipse IDE makes jar file creation relatively easy, but you have to play around with your settings a bit.

By the way, the FatJar plugin for Eclipse appears to be another option. I didn't use it because this worked but you can get more information here: http://fjep.sourceforge.net/

-Chris
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Simpkins:
...Layne, do you mean something like this?


...



Almost. For one thing, I think you need to enclose this path in "s since there is a space character in one of the folder names. Secondly, this indicates that Java can search the directory structure under the workspace folder for .class files. This isn't quite what you want. When adding JAR files to the classpath, you always need to include the full path to the JAR file, including its name. This is the same no matter how you specify the classpath for a program, whether that be by using the -cp option, the CLASSPATH system var, or the ClassPath: manifest attribute, you need to include any JAR files individually. So if you have a JAR file named "mypackage.jar" in a folder named "C:\java", you need the following:


HTH

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic