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 cannot find main class.program will exit. error in jar file creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "cannot find main class.program will exit. error in jar file creation" Watch "cannot find main class.program will exit. error in jar file creation" New topic
Author

cannot find main class.program will exit. error in jar file creation

gayathri murugesan
Ranch Hand

Joined: Dec 21, 2009
Posts: 32
i created a jar file in eclipse.

my manifest file is:

Manifest-Version: 1.0
Main-Class: EmailClient
Class-Path: mail.jar

when i click the jar file i am getting

cannot find main class.program will exit.

please help..


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

gayathri murugesan wrote:
cannot find main class.program will exit.


Obvious question. Does the jar file contain the main class (ie. EmailClient.class)? Can you do a "jar tvf" to show us what's in the jar?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
gayathri murugesan
Ranch Hand

Joined: Dec 21, 2009
Posts: 32

D:\pro>jar tvf test2.jar
0 Sat Mar 13 16:39:48 IST 2010 META-INF/
97 Sat Mar 13 16:39:48 IST 2010 META-INF/MANIFEST.MF
7044 Sat Mar 13 08:58:44 IST 2010 BasicJDBCDemo.class
8470 Sat Mar 13 08:58:44 IST 2010 Classifier.class
516 Sat Mar 13 08:58:44 IST 2010 ConnectDialog$1.class
543 Sat Mar 13 08:58:44 IST 2010 ConnectDialog$2.class
543 Sat Mar 13 08:58:44 IST 2010 ConnectDialog$3.class
4350 Sat Mar 13 08:58:44 IST 2010 ConnectDialog.class
3481 Sat Mar 13 08:58:44 IST 2010 Count.class
1377 Sat Mar 13 08:58:44 IST 2010 DataFileTable$1.class
954 Sat Mar 13 08:58:44 IST 2010 DataFileTable$2.class
954 Sat Mar 13 08:58:44 IST 2010 DataFileTable$3.class
591 Sat Mar 13 08:58:44 IST 2010 DataFileTable$4.class
8815 Sat Mar 13 08:58:44 IST 2010 DataFileTable.class
4141 Sat Mar 13 08:58:44 IST 2010 DataFileTableModel.class
900 Sat Mar 13 08:58:44 IST 2010 DownloadingDialog.class
479 Sat Mar 13 08:58:44 IST 2010 EmailClient$1.class
507 Sat Mar 13 08:58:44 IST 2010 EmailClient$10.class
507 Sat Mar 13 08:58:44 IST 2010 EmailClient$11.class
507 Sat Mar 13 08:58:44 IST 2010 EmailClient$12.class
506 Sat Mar 13 08:58:44 IST 2010 EmailClient$2.class
1296 Sun Feb 07 19:00:38 IST 2010 EmailClient$3$1.class
872 Sat Mar 13 08:58:44 IST 2010 EmailClient$3.class
1355 Sat Mar 13 08:58:44 IST 2010 EmailClient$4.class
984 Sat Mar 13 08:58:44 IST 2010 EmailClient$5.class
505 Sat Mar 13 08:58:44 IST 2010 EmailClient$6.class
1914 Sat Mar 13 08:58:44 IST 2010 EmailClient$7.class
553 Sat Mar 13 08:58:44 IST 2010 EmailClient$8.class
1259 Sat Mar 13 08:58:44 IST 2010 EmailClient$9.class
3355 Sat Mar 13 08:58:44 IST 2010 EmailClient$Checker.class
14459 Sat Mar 13 08:58:44 IST 2010 EmailClient.class
1993 Sat Mar 13 08:58:44 IST 2010 Learner.class
537 Sat Mar 13 08:58:44 IST 2010 MessageDialog$1.class
564 Sat Mar 13 08:58:44 IST 2010 MessageDialog$2.class
564 Sat Mar 13 08:58:44 IST 2010 MessageDialog$3.class
4696 Sat Mar 13 08:58:44 IST 2010 MessageDialog.class
2663 Sat Mar 13 08:58:44 IST 2010 MessagesTableModel.class
354 Thu Feb 25 07:25:44 IST 2010 WindowCloser.class
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

The javaw.exe program that runs JAR files is flawed. Any exception or error thrown from the main method is shown with that specific error message. Try running the JAR file from the command line:
- open a command window
- go to the folder where the JAR file is located (use "cd folder" to go into a folder)
- execute the following command: "java -jar test2.jar"

This will show you the exact stack trace of the error or exception instead of consuming it and showing a (too) generic error message.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
gayathri murugesan
Ranch Hand

Joined: Dec 21, 2009
Posts: 32
D:\pro>java -jar test2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: EmailClient
Caused by: java.lang.ClassNotFoundException: EmailClient
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: EmailClient . Program will exit.

gayathri murugesan
Ranch Hand

Joined: Dec 21, 2009
Posts: 32
before making the jar file i compiled an d ran the program .it worked properly. but when i make the jar file i am getting this CLASSNOTFOUNDEXCEPTION.


please help..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find main class.program will exit. error in jar file creation