Unable to execute .jar file

Martin D picture Martin D · Jan 26, 2014 · Viewed 13.9k times · Source

I'm having a problem with running .jar files. Here's what I've observed:

  • running executable .jar by doubleclicking doesn't do anything, not even start a process
  • running it from cmd by typing javaw myfile.jar doesn't do anything as well, I've redirected STDERR but it doesn't say anything
  • because of school requirements I'm developing in BlueJ, when I run my code directly from this IDE, it works and starts processes like java.exe or javaw.exe
  • when I try to compile my console program from cmd and then run it by java myclass, it works

I'm working on Windows 7 Professional with Java SE 7u51 JDK installed. I've already tried to uninstall anything that had "java" in its name and then install only JDK or only JRE. I've also tried to run jarfix or manually delete all .jar associations in registry. I've added my JRE path to other system variables. Nothing has worked for me.

Please do you have any idea what to try next? Thank you.

Resolved:
Thanks to the answers I've managed to resolve the problem with doubleclicking as well. I've just had to:

  1. set the JAVA_HOME variable
  2. restart the computer
  3. run jarfix

Answer

Ankur Shanbhag picture Ankur Shanbhag · Jan 26, 2014

Couple of quick solutions:

  • Use java -jar <jar-file-name>

    Note: This will be useful if your jar is Runnable

  • Use java -cp <jar-file-name> main-class-name

    Note: Specify the entry point with the class-name to start execution.