2

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

6
  • 1) What OS you are using? 2) If you are using Windows, right-click on your executable jar, go Properties and see whats under Opens with. Commented Sep 14, 2012 at 16:44
  • Yeah, I am on Windows. Under the opens item I got Java SE and WinRaR to open the file with. Commented Sep 14, 2012 at 16:47
  • Java -jar xyz.jar does open jar archives while java xyz.jar opens classes. therefore it will take the first it encounters. Commented Sep 14, 2012 at 16:58
  • @uml Is it Java (TM) Platform SE binary what you see?? And check if there is a manifest file. You can do that by opening your jar file with WinRAR. Commented Sep 14, 2012 at 17:01
  • Yeah, I have already checked whether it got that file. It is in, and the main class is pointed out correctly. Yes, at opens menu item you have an option to select Java SE binary. Commented Sep 14, 2012 at 17:04

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Correct, it points to Java 6. In fact I store java 6 at program files as 32 bit version, and then for 64 bits I have Java 7. I will simply remove Java 6
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.