Java application will start from CMD and Eclipse, but not double-click

I did a search and I see that many people had the same problem as mine, but none of the solutions worked for me.

Basically I have a Java Project in Eclipse, which is from my old Windows installation. I cleaned and rebuilt it because it did not compile at first, but now I exported it as a Runnable Jar. However, the only way to make the application appear is to make java -jar foo.jar on the command line or run it in Eclipse. If I double-click the JAR in Windows Explorer, nothing will happen, although I know that Java is correctly connected because other Runnable Jars work.

There is only x86 JRE in the project, which is indicated in it. Path path libraries and all of the files listed appear to exist. I am using Windows 7 HP.

Update : Sorry, but I just found that no other Runnable Jars work. If they are wrapped in launch4j, they work though ...

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

+4
source share
5 answers

Some registry values ​​or file associations are probably confused. Recycling all existing JREs and JDKs and reinstalling them should fix your problem.


Alternatively, you can fix this by manually changing the registry value here: HKLM > SOFTWARE > Classes > jarfile > shell > open > command My value

Type: REG_SZ

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

Of course, you want this path to point to your javaw.exe and make sure that you have additional arguments.

+7
source

I also had a problem with the same problem when I was working with the Spring toolbox.

You can use the following steps: -

  • Right-click on the project β†’ export β†’ Runnable jar file β†’ (Here, in the processing of the library, there are three options, you need to choose the middle one, that is, the batch library, in the generated jar.It will also pack an external dependency).

- In my case, my executable jar was executed only in my environment on which I created this JAR. Initially, I chose the first option to create a JAR ie retrieve the necessary libraries in the required JAR.but, but that was wrong.

It can help you. Let me right if I am wrong.

+1
source

Since you can run the JAR that launches the command line, I believe that your problem is with which version of Java is configured to run the file with a double click.

To find out which version successfully runs the file from the command line and sets it to open default JAR files:

  • Open a new command prompt window.
  • Run echo %path% . Among the path values, you should find one pointing to the bin folder of one of the installed versions of Java. Copy this path somewhere.
  • Browse to the JAR file you want to run. Right-click JAR β†’ Open with β†’ Select the default program ... β†’ Browse ...
  • Go to the path you copied in step 2. (the easiest way is to paste it into the address bar)
  • Double-click javaw.exe.
  • Click OK.

Now you can run the jar file. Please let me know if your problem persists.

+1
source

I made a jar and keep it on my desktop. Then I double clicked on the jar and it works great for me.

Like me and what I have: in my main class, do some operation, and at the end I add to Thread.sleep(25000); to hold the program for a few moments. After each double click on the exported jar, I found a new javaw.exe process in the system process tree . I noticed this in the task manager. and after 25000ms the javaw.exe process is over. Since my application does not integrate any GUI, why didn’t I see any changes in the GUI for the corresponding process. I am sure that if my application has some kind of graphical interface, I will definitely get a corresponding GUI window for each launch.

Common errors: when exporting a project from Eclipse as an executable JAR file, it is exported with the selected Eclipse startup configuration and special Eclipse startup shells. Now, if the configuration does not match, when you try to start it with a double click, you will not be able to see this error. If you run it from CMD, then you will surely get an error log.

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

This works fine for me. I used the same jar from different systems and saved it in another place.

-one
source

Really stupid idea here.

Have you tried to elevate the privileges of what you open .jar with (java.exe or javaw.exe)?

Right-click on the program β†’ Properties β†’ the compatibility tab β†’ at the bottom of the "Run this program as administrator" button.

There is a possibility that you have elevated privileges in the command window, which may allow it to run.

-one
source

Source: https://habr.com/ru/post/1497982/


All Articles