Reputation: 1189
I have Java GUI application in Java SE version 7 which I run on Windows 7 64 bits. When I try to run it clicking on jar file the pop up Window is saying 'Cannot find the main class or load it:...'. When I run the same jar file via command line in this way: java -jar app.jar' it works fine. If you try to run it in this way: 'java app.jar' it throws the same error. On Eclipse IDE it works fine. The jar file has been created by the Eclipse IDE as Running jar file. I have created one more project with simple GUI. It has the same problems as above example. What might be the problem? My goal is to run the app once you click on the jar file. Best regards
Upvotes: 2
Views: 940
Reputation: 1542
You need to make a manifest file, under the Meta-INF folder. If there's already one there, add the line
main-class: [class name].class
And try that (not sure if there's supposed to be a space after the colon)
Upvotes: 0
Reputation:
Sounds like on your system the .jar
extension is registered to run with Java6 and your application needs Java7.
On the commandline type the following command to find out how the .jar
extension is registered:
assoc .jar
It will show something like this:
.jar=jarfile
(Note: on your system it might be a different type name. Anything after the =
is the typename that you need to use)
Now you need to find out which command is associated with the typename jarfile
by using:
ftype jarfile
On my system it shows:
jarfile="C:\Programme\Java\jre7\bin\javaw.exe" -jar "%1" %*
If that is not pointing to a Java7 installation you need to change that e.g. through the ftype
command or through the Control Panel.
You might also be able to switch the default Java VM by using the "Java" applet in the Control Panel.
Upvotes: 4