Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executable jar Could not find the main class

 
Jo Young
Ranch Hand
Posts: 34
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15632
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jo Young
Ranch Hand
Posts: 34
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jo Young
Ranch Hand
Posts: 34
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51390
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jo Young wrote: . . . it works now thank you! :-)
I bet you're relieved at that
 
Jo Young
Ranch Hand
Posts: 34
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic