my dog learned polymorphism
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
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

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

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: 15084

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 8 API documentation
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:
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
Could not find the main class: myTimer. Program will exit.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20274

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.

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 Timer.myTimer.class Timer.timeClock.class

instead of

jar cfm PushupTimer.jar 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

Joined: Oct 13, 2005
Posts: 46362
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!
I agree. Here's the link:
subject: Executable jar Could not find the main class
It's not a secret anymore!