Results 1 to 18 of 18
- 11-07-2011, 02:27 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
"Cannot find main class" error when creating a .jar!
Hello. I have a class called GUI.java and (of course) it contains a main method and I would like to make it a jar file for execution. I've tried 100 times with different options, tried using eclipse to do it for me, tried using the command line and making my own manifest file, everything. Whenever I double click the jar I created, it says "Cannot find main class: GUI. Program will now exit". What can I do??
- 11-08-2011, 01:20 PM #2
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
bump.. no responses yet??
- 11-08-2011, 02:13 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 31
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
Hi, have you tried calling the Jar from command line?
Java Code:java -jar FileName.jar
- 11-08-2011, 03:26 PM #4
Senior Member
- Join Date
- Aug 2011
- Posts
- 249
- Rep Power
- 2
Re: "Cannot find main class" error when creating a .jar!
When you export your project as a jar in the last step it asks you to specify the main class.
Do that!
- 11-08-2011, 03:40 PM #5
Re: "Cannot find main class" error when creating a .jar!
Check that the jar file contains a manifest file with a Main-Class: entry that has the correct path to your class.
- 11-08-2011, 06:42 PM #6
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
I specified the Main class in Eclipse and my manifest file (from when I was trying to create the jar myself) contained Main-Class: GUI with two carriage returns (enter key) afterwards.
- 11-08-2011, 06:56 PM #7
Re: "Cannot find main class" error when creating a .jar!
Is the correctly formatted manifest file in the jar file?
- 11-09-2011, 12:32 AM #8
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
Yes it is in the jar file when I open it with 7-zip.
- 11-09-2011, 12:48 AM #9
Re: "Cannot find main class" error when creating a .jar!
If the manifest is in the jar and is in correct format, then the java command should start the class named by Main-Class.
If it does not, then something is wrong and you need to check again.
Open a command prompt, change to the folder with the jar file and enter:
java -jar <YOURJARFILENAMEHERE>.jar
Copy the console contents here.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 11-09-2011, 04:20 AM #10
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
OP,You can try this.
Or, you can try this.
JAVA [creating Jar files] « Me, when programming
As you have created JAR file you should just try theportion.Ways to update a jar file with manifest……Don't Forget to try yourself before asking others help.....
Press REP, if you find their advices/solutions effective.
- 11-09-2011, 02:35 PM #11
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
The strangest thing: when I opened a command window, went to my directory and typed java -jar G.jar (G.jar is the name of my jar file), it ran my jar! But whenever I double click it I get the "Cannot find Main Class GUI.java"... Anything?
- 11-09-2011, 02:42 PM #12
Re: "Cannot find main class" error when creating a .jar!
That message is different from the one you posted earlier.I get the "Cannot find Main Class GUI.java".
Are you sure it is complete and correct?"Cannot find main class: GUI. Program will now exit".
Can you look in the Windows registry and see what the command line is for the jar files?
- 11-09-2011, 04:21 PM #13
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
@OP
I have faced the same problem. I use XP,Windows7 and ubuntu. My jar files works on xp and ubuntu fine. But in W7 I got the message "Cannot find Main Class". Try your JAR files on another pc. And You can change OS's default file type.Make sure that when double clicking It is opened by javaw.exeDon't Forget to try yourself before asking others help.....
Press REP, if you find their advices/solutions effective.
- 11-09-2011, 04:30 PM #14
Re: "Cannot find main class" error when creating a .jar!
I have several different versions of java on my machine. I get different results when I try to open a jar file that does not have a manifest file with different versions of java.
One gives me this error window:
- 11-09-2011, 05:22 PM #15
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
The first error I posted was correct. I wrote the second one from memory, sorry. I'm running windows 7 x64 so this must be the issue. Thanks everyone
- 11-09-2011, 05:27 PM #16
Re: "Cannot find main class" error when creating a .jar!
What is the full text of the error message you get?
Here's what I get when I leave out the -jar option:
Microsoft Windows XP [Version 5.1.2600]
D:\JavaDevelopment>java acme.jar
Exception in thread "main" java.lang.NoClassDefFoundError: acme/jar
Caused by: java.lang.ClassNotFoundException: acme.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: acme.jar. Program will exit.
- 11-10-2011, 02:43 AM #17
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Re: "Cannot find main class" error when creating a .jar!
It's nothing like that. A window comes up saying "Cannot find main class: GUI. Program will now exit" and that's all. It works from the command line and works on my windows vista desktop.
- 11-10-2011, 12:20 PM #18
Similar Threads
-
"Could not find the main class" when omitting "-jar"
By b0rt in forum Advanced JavaReplies: 11Last Post: 08-18-2011, 10:54 PM -
Receiving error "Could not find the main class"
By Kalpesh in forum New To JavaReplies: 2Last Post: 02-02-2011, 06:31 PM -
Error message "could not find the main class"
By srwpchelp in forum New To JavaReplies: 8Last Post: 12-23-2010, 09:15 PM -
"Could not find the main class" for Linux Command Line Compile
By tetelee in forum New To JavaReplies: 3Last Post: 08-25-2010, 10:21 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks