4

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

Andy
  • 3,600
  • 12
  • 53
  • 84
  • But right click, open with, java runtime environment works? The `start` command which executes on double click does not now what to do with the jar file. My system opens them with winrar. – Matten Aug 20 '13 at 11:20
  • @Matten No, if I right click and open with JRE (which is default anyway) nothing happens – Andy Aug 20 '13 at 11:22
  • As stated @Matten, I've tried all of the answers there and none of them help! – Andy Aug 20 '13 at 11:24
  • You say that "nothing happens". Did you check in the Windows task manager wether a _java_ or _javaw process_ starts on double clicking ? – jeroen_de_schutter Aug 20 '13 at 11:36
  • @jeroen_de_schutter Yes, no new processes are started when I double click. It doesn't even look like anything starts and then stops again quickly. – Andy Aug 20 '13 at 11:55
  • This one is intriguing. have you allready tried try to launch it in the command prompt with _javaw_ instead of _java_ ? -> `javaw -jar foo.jar` – jeroen_de_schutter Aug 21 '13 at 09:00
  • @jeroen_de_schutter I know. I haven't tried it with 'javaw' because I didn't see much point as it works fine with the command prompt already but I'll give it a shot. 1 min. – Andy Aug 21 '13 at 12:47
  • Yep. 'javaw' works just the same as 'java'. The program launches fine. The problem is just with double click – Andy Aug 21 '13 at 12:58
  • I suppose you have made sure your mouse is not malfunctioning ? ;-) Do you have maybe multiple JREs or JDKs installed on your machine ? Then it might be possible that the default program which is assigned to jar. files is another version than the one in your %PATH% system variable which points to the location of java.exe. Another thing you can and should do is enable the Java console in the Java control panel, so that it pops up everytime you start a JVM on your machine. Maybe there is some useful information logged there. – jeroen_de_schutter Aug 21 '13 at 13:18
  • Yes, my mouse is fully functional! I do have multiple JREs and a JDK though. Just remind me where the PATH system variable should point? – Andy Aug 21 '13 at 13:56
  • Take a look at this topic for finding out where your JDK and JRE are located : http://stackoverflow.com/questions/4681090/how-do-i-find-where-jdk-is-installed-on-my-windows-machine – jeroen_de_schutter Aug 22 '13 at 07:49
  • Hmm, something very odd. I have JDK installed, as well as JRE 6 and JRE 7, but the output of `for %i in (java.exe) do @echo. %~$PATH:i` only shows the JDK, and the environmental variables are set correctly. – Andy Aug 23 '13 at 13:47

4 Answers4

8

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.

Lunchbox
  • 1,603
  • 11
  • 14
  • Indeed, there is no need to re-install Windows. It is probably one of your Java versions that is messed up. Uninstall them all and get yourself one fresh JDK (which has the JRE included already). – jeroen_de_schutter Aug 29 '13 at 08:47
  • The answer! Finally! Uninstalling (then rebooting) and re-installing my JREs did the trick. Thank you very much – Andy Aug 29 '13 at 11:17
1

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.

Avyaan
  • 1,285
  • 6
  • 20
  • 47
  • Thanks for your answer but I have tried each option when compiling, but I still have the same problem. – Andy Aug 20 '13 at 13:06
1

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.

Decimix
  • 373
  • 1
  • 8
  • Thanks for the answer. I did as you said, and got the relevant path value, then copied it into the file chooser and selected `javaw.exe` but still nothing :( – Andy Aug 25 '13 at 20:40
  • Sorry about that. Is it only one JAR file that you're having trouble with, or is the problem system-wide? @Andy – Decimix Aug 25 '13 at 22:07
  • No worries. And no, I've now discovered that no executable JARs will run on double click (system-wide). – Andy Aug 26 '13 at 06:46
  • Is Java(TM) Platform SE binary listed in the Open With menu of JAR files (right click -> Open with)? If so, what happens when you select it? @Andy – Decimix Aug 27 '13 at 14:18
  • It certainly is, but still nothing happens. No luck with your Edit either. – Andy Aug 27 '13 at 16:51
  • Try the right click → Open With action together with java.exe instead of javaw.exe. This will give you a console window which might show error output. – Holger Aug 28 '13 at 15:47
  • Reassociating javaw.exe might do the trick at this point in time, as I believe the console window you see opening is a result of it currently being associated with java.exe. @Andy – Decimix Aug 28 '13 at 20:15
  • @Decimix Yep, it did do the trick... well, reinstalling the JREs did. Thanks for your help. – Andy Aug 29 '13 at 11:20
-1

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.

Pradip
  • 3,189
  • 3
  • 22
  • 27
  • Thank you for your answer. I know you're trying to help but I do know how to program and use Eclipse. I have done everything you've mentioned and JARs still don't open on my system. Also, please read my question - I have stated that it is not just JARs I create. – Andy Aug 27 '13 at 10:40