Windows, run JAR with double click

1.1k views Asked by At

I'm experimenting with Java for the first time. I'm using Intellij IDEA and creating a simple app. In the IDE it's working fine, then I create a JAR artifact and run it like this: java -jar myappname.jar with no problem.

Now I would like to start the same JAR with double-clicking it from explorer but nothing happens, why?

Please note that if I double click another JAR (sikulixsetup-1.1.3.jar) it starts correctly and show the gui, so the problem is not type association in windows.

My test app does not have a gui but I know if it runs correctly because it's automating windows using Sikulixapi library, so I see if it's doing something or not.

thanks!

3

There are 3 answers

0
Dado On BEST ANSWER

Ok, I solved my issue. Usually the JAR runs without any problem by simply double clicking it in windows, in my case it was not running becase the .jar files was associated to the 32bit version of javaw.exe while the code in the JAR was expecting the 64bit environment. Changing the .jar type association in windows from 32bit to 64bit version of javaw.exe solved the issue

1
Antoniossss On

Its because jar is not executable binary but plain zip archive. OS cannot execute that. That is why you must use java executable and pass archive as argument to run your application.

If you want your app to be "clickable" you must use some wrapper solution like http://launch4j.sourceforge.net/

0
Gabriel Messas On

Change the default program to use while opening the file from one Java to the other (32 to 64 bit or vice-versa).