File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Executable jar Could not find the main class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executable jar Could not find the main class" Watch "Executable jar Could not find the main class" New topic
Author

Executable jar Could not find the main class

Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

I'm back... I've had this problem once already when I only had one class in the jar, I went back and added a second class to make it user friendly because I realized that the way I wrote it originally in order for the user to turn off the program they would have to go into task manager and stop javaw.exe process... so I made a second class that has Swing on it and creates a window... and now it is having the problem of not being able to find the main class that is in the manifest again... and I have tried everything that I was directed to do the last time that finally got the other one fixed as well as all the different things that didnt work last time and it keeps giving me the same error...

currently I have...

C:\JarFile>C:\Oracle\Middleware1013\jdk160_18\bin\jar -tf PushupTimer.jar
META-INF/
META-INF/MANIFEST.MF
myTimer.class
timeClock.class

C:\JarFile>C:\Oracle\Middleware1013\jdk160_18\bin\jar -xf PushupTimer.jar META-INF/MANIFEST.MF

Manifest-Version: 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Main-Class: myTimer

any ideas?

I tried setting Main-Class to Timer.myTimer and saving the class files to Timer.myTimer.class and Timer.timeClock.class (the package name for the classes is Timer so I thought that maybe having the files saved by just their class names and then it gets into the class and it is in a package might have been the problem... this was not the case)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

Maybe this is the problem: Make sure there is an empty line at the end of the MANIFEST.MF file. There's a known problem where Java will not interpret the last line in the manifest if there is no empty line at the end; the tutorial warns about this:
The Java Tutorials wrote:
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


What error message exactly do you get when you enter the following command (please copy & paste the complete error message)?

C:\Oracle\Middleware1013\jdk160_18\bin\java -jar PushupTimer.jar


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

yes there is a line at the end of the manifest I had that problem the last time.

the error I get is:

Exception in thread "main" java.lang.NoClassDefFoundError: myTimer (wrong name:
Timer/myTimer)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: myTimer. Program will exit.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

You put your class inside a package called Timer. That means that a) the class name is Timer.myTimer, and it should be included in the manifest file like this, and b) file myTimer.class should be stored in a folder called Timer inside the JAR file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Rob thank you I actually had tried doing it like that also with the folder and stuff but when I tried to create the jar I created it like

jar cfm PushupTimer.jar Manifest.mf Timer.myTimer.class Timer.timeClock.class

instead of

jar cfm PushupTimer.jar Manifest.mf Timer/myTimer.class Timer/timeClock.class

I just looked back at the tutorial I had used to do this originally and realized that there was a "/" between the folder and the class not a "."

it works now thank you! :-)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Jo Young wrote: . . . it works now thank you! :-)
I bet you're relieved at that
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

lol yep... now I can do my pushups in peace... woohoo... lol but I think I might start my own company off of this thing!! lol I've now started distributing it out to the rest of the office anyone want their own 30 minute timer??? it has a cool little window with a clock with hours minutes and seconds in military time and says "Do your pushups" every 30 minutes on the 00 and the 30 of the hour!
 
jQuery in Action, 2nd edition
 
subject: Executable jar Could not find the main class