user1102901
user1102901

Reputation: 565

Java jar running

Any idea why

java -jar jarname.jar

works, but double clicking the jar gives a

"Could not find the main class:"

error? Manifest is correctly placed and double clicking was working until recently, but all of a sudden it gives that error. I'm not sure what changes I made though.

EDIT:
The command I used to create the jar was (in cmd):

jar cfe jarname.jar files.Main *

Main is part of the package files.

Upvotes: 0

Views: 85

Answers (3)

user1102901
user1102901

Reputation: 565

It seems to have been some weird compiler version problem. When I complied the class files using an older version of java, then compiled it into a .jar file, it was able to run.

Upvotes: 0

matcauthon
matcauthon

Reputation: 2261

Some time ago I had a comparable problem. And it was caused by multiple JDK/JRE versions on my machine. What is used by double-clicking differs from what is used by typing jar in a shell.

I think JarFix could help. Or you lookup what is associated with double-click in the file-associations (reinstall java might also help)

Upvotes: 0

HashimR
HashimR

Reputation: 3833

Add this entry in your manifest file:

Main-Class: com.abc.def.YourMainClass

Hope this'll help!

Upvotes: 1

Related Questions