Could not find the main class. Progam will exit

Guys,

I have read same/similar topics on this forum. However I was not able to solve my problem. So help is needed to my specific problem.

Here is the problem desciption:

I have java program with External jars. I am using Eclipse. In eclipse I managed to run ok and I am getting the output. I created jar file using Eclipse. Now I am trying to run this jar file by double clicking on it. I am getting the error message "Could not find the main class. Program will exit."

Please advise. Also I am not good at using DOS. So please advise, so that I can do things in Eclipse and/or Windows.

I appreciate any help, Thanks

[654 byte] By [ryellapua] at [2007-11-26 17:21:52]
# 1
The manifest needs to specify a main class: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
zadoka at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 2

1) learn to use command-line interfaces. programmers who are scared of them never get very far

2) sounds like you need a proper manifest file (MANIFEST.MF). eclipse can generate this for you, but in order to understand what it's for how it works, etc, you're going to have to bite the bullet and read a [url=http://java.sun.com/docs/books/tutorial/deployment/jar/]tutorial[/url]

georgemca at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 3
I mentioned it my manifest.mf.Here is how it looks:Manifest-Version: 1.0Main-Class: Excel.BrdpInExcel
ryellapua at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 4

I also tried changing my manifest.mf with Class-Path option to specify external jars.

Manifest-Version: 1.0

Class-Path: C:\Program Files\Java\jdk1.5.0_10\lib\comfyj-2.1.jar C:\Program Files\Java\jdk1.5.0_10\lib\jexcel-1.0.jar C:\Program Files\Java\jdk1.5.0_10\JExcel\lib\jniwrap-3.1.jar C:\Program Files\Java\jdk1.5.0_10\JExcel\lib\winpack-3.0.jar

Main-Class: Excel.BrdpInExcel

ryellapua at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 5
> I mentioned it my manifest.mf.> > Here is how it looks:> Manifest-Version: 1.0> Main-Class: Excel.BrdpInExcelMake sure the manifest has a newline after the main-class line.
zadoka at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 6
Yes, I havce newline after the main-class line.
ryellapua at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 7
> Yes, I havce newline after the main-class line.Does BrdpInExcel have a main method?Is it just under the package Excel?If both of these are true, I am out of guesses. Take a look at the tutorial link I posted and work through a simple example.
zadoka at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 8
Try creating the jar manuallyjar cmf manifest_file target_file.jar sourcesFor examplejar cmf Manifest.txt RunMe.jar *.classCheers
duckbilla at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 9
Yes. BrdpInExcel has main method and it is in the package Excel.One more thing is I tried simple HelloWorld. I created jar for that and ran by double clicking on the jar file and It didn't give any error message.
ryellapua at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 10

> Yes. BrdpInExcel has main method and it is in the

> package Excel.

> One more thing is I tried simple HelloWorld. I

> created jar for that and ran by double clicking on

> the jar file and It didn't give any error message.

Well, look at the differences between to the two and that will narrow down your problem.

zadoka at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 11

OK, I tried to work out what was the problem. Nothing worked out.

Here is My Jar file and error response when running using java -jar ...:

C:\DOCUME~1\RYELLAPU>jar -tvf workspace\BrdpCount\BrdpCount.jar

310 Mon Feb 05 17:56:02 GMT 2007 META-INF/MANIFEST.MF

2939 Mon Feb 05 17:35:40 GMT 2007 testexcel/BrdpExcel.class

620 Fri Feb 02 16:07:18 GMT 2007 .classpath

385 Fri Feb 02 16:06:28 GMT 2007 .project

301 Mon Feb 05 17:38:56 GMT 2007 Manifest.mf

C:\DOCUME~1\RYELLAPU>java -jar workspace\BrdpCount\BrdpCount.jar

Exception in thread "main" java.lang.NoClassDefFoundError: testexcel/BrdpInExcel

and my manifest file looks below:

Manifest-Version: 1.0

Class-Path: C:\Program Files\Java\jdk1.5.0_10\lib\comfyj-2.1.jar C:\Program Files\Java\jdk1.5.0_10\lib\jexcel-1.0.jar C:\Program Files\Java\jdk1.5.0_10\JExcel\lib\jniwrap-3.1.jar C:\Program Files\Java\jdk1.5.0_10\JExcel\lib\winpack-3.0.jar

Main-Class: testexcel.BrdpInExcel

I Included Class-Path option for external Jar files.

Any advise will be appreciated.

Thanks,Yellapu

ryellapua at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 12

Another thing to mention is, I tried simple HelloWorld program(So no external jar files). And it works fine. In this case I don't have any Class-Path option in my manifest file. So the problem is when I update maifest file with Class-Path option for External jar file, it is giving the error message.

ryellapua at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 13
could it be that your class is called "BrdpExcel" but in the manifest you have written "BrdpInExcel" ?
jsalonena at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 14

You should also avoid hard-coding the external jar paths in the manifest file. If possible, move/copy the external jars to the same directory (or a subdirectory of this directory) as your jar and use

Class-Path: external1.jar external2.jar ...

// OR (subdirectory external)

Class-Path: external/external1.jar external/external2.jar ...

Cheers

Message was edited by:

duckbill

duckbilla at 2007-7-8 23:49:51 > top of Java-index,Java Essentials,New To Java...
# 15

Eclipse gave me the exact same problem a few months ago, so I deleted all my external JARs, downloaded them again, switched to NetBeans, and haven't had a problem since.

I had looked through the tutorials on classpath, manifest files, etc. I had asked here, at the Eclipse forums, and searched the web. Eventually, I decided to screw Eclipse and use NetBeans.

If all else fails, download the JARs again, try a different IDE, or try compiling everything directly from the command line.

Djaunla at 2007-7-21 17:02:12 > top of Java-index,Java Essentials,New To Java...