delca7
delca7

Reputation: 97

"Could not find the Main class" when opening a .jar file

When I try to open a .jar file by double-clicking it I get this message that "Could not find the Main Class", however it works when opening it with the command line.

I've been looking for a solution for some days, I found a lot of people asking the same questions, some of the answers I found suggest that the main class is not declared in the manifest.mf, however I checked it and it is declared, here is my manifest.mf

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_13-b20 (Oracle Corporation)
Class-Path: 
Main-Class: my_pack.Mainprog
[empty line]
[empty line]

I tried to run the jar that NetBeans builds, also with the fat jar plugin for eclipse and always get the same error.

Upvotes: 3

Views: 564

Answers (1)

Sauer
Sauer

Reputation: 1469

What I would do is: Create a dummy project in your Netbeans and export it as a runnable jar. Then take your manifest and the dummy-project manifest and compare it.

Manifests are really a pain in the code. They need to be absolutely correct formatted. Take care on trailing whitespaces, missing/additional empty rows etc...

Maybe check the Java Version, you are using. Make sure, that your command line uses the same one, like setup in your environment variables. Maybe there are doubled declarations...

Which java.exe is associated with *.jar files in windows explorer? Try exactly THIS java.exe to run your jar from the CLI. Same issue then?

Good luck!

Upvotes: 1

Related Questions