简体   繁体   中英

Java application will run from CMD and Eclipse but not double click

I've done a search and I can see that a lot of people have had the same problem as me, but none of the solutions have worked for me.

Basically I have a Java Project in Eclipse that is from my old Windows Installation. I've cleaned and rebuilt it because at first it wouldn't compile, but now I have it exported as a Runnable Jar. However, the only way I can get the application to appear is to do java -jar foo.jar in command prompt, or run it in Eclipse. If I double click the JAR in Windows Explorer nothing happens even though I know that Java is associated correctly because other Runnable Jars work.

The project only has the x86 JRE listed in it's Build Path Libraries and all the files listed appear to exist. I'm running Windows 7 HP.

Update : I'm sorry, but I just discovered that no other Runnable Jars are working either. If they are wrapped with launch4j they work though...

Edit : The Runnable Jars that I export from Eclipse do work fine on other systems and load on double click

Some registry values or file associations are probably messed up. Wiping off all of your existing JRE's and JDK's and re-installing them should fix your issue.


Alternatively you may be able to fix it by manually editing the registry value here: HKLM > SOFTWARE > Classes > jarfile > shell > open > command My value is

Type: REG_SZ

Data: "C:\\Program Files\\Java\\jre8\\bin\\javaw.exe" -jar "%1" %*

You'd of course want that path to point to your javaw.exe, and make sure you have the additional arguments.

I was also facing the same problem while i was working with Spring tool suite.

You may use the following steps:-

  • Right click on project -> export -> Runnable jar file -> (Here,In library handling,there are three options,you have to choose middle one ie package required library into generated jar.It will package external dependency also).

-In my case, my runnable jar was only executing on my environment ie on which i have created that JAR. Initially i have selected the first option to create JAR ie extract required libraries into required JAR.but that was not proper.

It may help you.Let me correct if i am getting wrong.

Since you are able to run the JAR running the command line, I believe your issue is related to which version of Java is set to run the file when it is double-clicked.

To find out which version is successfully running the file from the command line and set it to open JAR files by default:

  1. Open a new command prompt window.
  2. Run echo %path% . Among the path values, you should be able to find one pointing to the bin folder of one of the installed versions of Java. Copy this path somewhere.
  3. Navigate to the JAR file you would like to run. Right click the JAR -> Open with -> Choose default program... -> Browse...
  4. Browse to the path you copied in step 2. (the easiest way is to paste it into the address bar)
  5. Double click javaw.exe.
  6. Click OK.

You should now be able to run the JAR file. Please let me know if your problem persists.

I have made a jar with and keep it on desktop.Then,I double clicked on the jar and it working fine for me.

How I and what I have monintored: In my main class, perform some operation and at the end I add on Thread.sleep(25000); to hold the program for few moments. After every double click on the exported jar I found one new javaw.exe process added in the system process tree. I have noticed it on Task manager. and after 25000ms respective javaw.exe process ended. As my application does not cointain any GUI that's why I have not seen any GUI changes for the respective process. I'm Confident that if my application have some GUI, I will surely get the respective GUI window on every run.

Common mistakes : when we export a project from Eclipse as Runnable JAR file, it is exported with selected Eclipse launch configuration and Eclipse specific launch wrappers. Now if the configuration does not match when you are trying to run it via double-click you will not be able to see the error, If you run it from CMD then surely you will get the error log.

To create standard executable JAR file : To create a standard executable JAR file, you can export as JAR file and specify the main class in last screen of the wizard.

That's working for me fine. I used the same jar from different system and keeping it different location.

Really silly idea here..

Have you tried elevating the privileges of whatever you are opening the .jar with (java.exe or javaw.exe)?

Right click on the program -> Properties -> Compatibility tab -> Check the "Run this program as administrator" button at the bottom.

There is a possibility that you have elevated privileges on your command window, which may be letting it run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM