1

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!

Dado
  • 95
  • 1
  • 11
  • Its because jar is not executable but plain zip archive.Thats why you must `java -jar myappname.jar` – Antoniossss Nov 08 '18 at 16:08
  • the problem was my jar was able to run just using 64bit version of java, not 32 so I had to associate jar file to 64bit java.exe – Dado Nov 13 '18 at 10:53

3 Answers3

1

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

Dado
  • 95
  • 1
  • 11
0

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/

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • thanks, I know, as I wrote in my post I have another JAR, and it starts correctly with a double click, so it's not correct that I need to use java or convert it to an exe, there should be another way. What I'm not sure is if the other jar is working with double click because has a GUI and mine not. If I understand well launch4j create an .exe incapsulating the JAR , ok could be fine for me, but I really want to understand why the other JAR is working and how to achieve the same... thanks – Dado Nov 08 '18 at 17:51
0

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