Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 574
Andy Avatar asked Jan 12 '23 14:01

Andy


2 Answers

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.

like image 102
Lunchbox Avatar answered Jan 25 '23 22:01

Lunchbox


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 i.e package required library into generated jar.It will package external dependency also).

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

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

like image 42
Amit Singh Avatar answered Jan 25 '23 22:01

Amit Singh