Windows, run JAR with double click - java

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!

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

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/

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

Related

AEM jar not starting

I have an AEM jar file AEM_6.5_Quickstart. I am trying to get it running but facing issues.
First thing is my jar is not identified as normal on my system like other jars, as you can see there is no icon associated with my jar file.
Second is when i double click on it to run it i get the below prompt to choose the program to run it with, which ideally should not appear. I was getting errors when i was running maven command to generate project using zulu jdk so i had installed jdk from oracle website, now that is removed from my system and when i double click on jar file i still get the option to run it using oracle jdk
Third problem which i am facing is that when i run the jar using zulu x64 Architecture as in above image it starts the jar but i get the below error when i go to localhost:4502
i google searched for solutions and found that indexing might be the problem so i deleted the file at crx-quickstart/repository/index after stopping the jar. When i restart it it gets stuck and doesnt start for some reason as in below picture, the progress bar doesnt move even though i waited for hours. I also made sure that sling authenticator service was running.
This is the output in case it helps for the java version being used and the path is setup as C:\Program Files\Zulu\zulu-11\bin. I am unable to fix this issue, any help is much appreciated.
First, delete the whole crx-quickstart directory (since this is a local environment being set up for the first time), and this way you will have a clean start. After that, maybe the .jar extension is missing from the filename, please add it. Finally, it is easier to use a .bat or .sh script (you can customize parameters and runmodes for AEM). But for a first run, quick setup with the default sample content, just try java -jar AEM_6.5_Quickstart.jar
It seems like windows messed up with your java versions, you can go and fix your windows JDK references from the registry, you can do that by pressing win + R then type "regedit", once open look for the next value:
"HKEY_CLASSES_ROOT\jarfile\shell\open\command" then open the "default" value and check that your path is correct, mine for example is :
"C:\Program Files\Java\jdk1.8.0_202\bin\javaw.exe" -jar "%1" %*
use mine as reference only change the first part between quotes for your path to the JDK.
Usually that should fix it, but some times there are some other registry references that ruin your jar files association, if you can open PowerShell/cmd or bash terminal type java -version and get the proper version of your Java installation, another workaround can be opening terminal, navigate in terminal where your jar lives and then type
java -jar yourJarFile.jar

.exe from launch4j works, but not on all computers

I wrap my Java project's JAR file to an .exe file using launch4j, which works fine on my dev machines and several other computers. However, one user reported he cannot run the .exe file on his machine, as a popup message tells him
Could not find the main class.
Interestingly, the user is able to run the JAR file directly on the same computer, either by calling it via java -jar from command line, or directly by double-clicking the JAR file in the Windows explorer (or via shortcut). That user has installed latest JRE.
I have seen on other threads here that this problem could occur because of invalid Manifest files, e.g. if the main class is missing there. However, I think this is not the case, because it's working fine if the JAR is called directly as said.
So I assume the problem is somewhere with my launch4j configuration. There I have not specified a custom Manifest file, only the input JAR file and the output .exe file.
I thought my launch4j config would be fine, because the .exe is running on several machines using different Windows versions. This is the first time I encounter that problem, but as said with the .exe file only.
Any ideas?
We just found the problem with that one client machine. It had the 64 bit version of the JRE installed, that was causing the problem. After replacing it with the 32 bit JRE version the .exe file can be correctly started again.
Yes,even I faced this problem. I used jar2Exe instead of launch4j. It's working fine.You better use it.

izpack installer 'is not marked as executable' on ubuntu

I created an installer that works fine on OS X and Windows. On Ubuntu I get the message "The file '/media/administrator/UNTITLED/installer.jar' is not marked as executable" when trying to right click and launch with Java.
It works after I set the executable bit, but that's not the experience I expect from an installer.
The installer was built on OS X and I also tried to preset the executable bit via ant chmod, but I assume that This is lost or prevented on Ubuntu for security reasons?
Is there a way to reliably preset the executable bit?
If not, are there alternative tools for creating double-clickable Installers that work on Ubuntu without users having to manually set permissions?
Seems the answer is "It's not possible. You need to create a .deb package to get the desired behaviour".
Right click on the file and go properties, then select permissions and check "Allow executing file as program".
EDIT:
Or alternatively, set the jdk/jre as default program for .jar type. (this is one thing you can not control by your installer)

Simple swing application. The jar file runs on my computer, but not others

This is my first question, so apologies for any mistakes. I'll try and give all the info I can. Basically I've written a simple swing application which just loads in image into a JPanel and displays it. I'm using Netbeans 7.1 and I have the latest version of the Java SDK.
Anyway, I've used the "Build" feature in NetBeans 7.1 to deploy my application into a Jar file. When I double click the Jar File on my PC, it runs without a problem. However when I put it on other computers (Tested on 2 others so far, both with the most current JRE) it fails to open, citing the following error:
could not find the main class: swong.Startup. Program will exit
swong is my package name, and Startup is the location of my main method. I have checked the manifest file which is created with Netbeans' build, and it[the manifest] does indeed contain the location of my main method class.
From searching, I've come across similar issues in which the classpath is set wrongly, but I don't understand how this could cause my particular error.
If someone could help me, I would be over the moon. I've been studying java for a year or so, and I've got a good handle down, but I've NEVER been able to make a Jar that runs on a computer which wasn't my own. So, 10 points and thanks in advance.
xo.
EDIT: Thank you for the responses. I'm doing shift work and swamped, but I will test and poke with these responses tomorrow and provide more information. Thanks again. xo
I had d same problem while distributing my app. There is 1 solution that you create a batch file with 'java -jar AppName.jar' and asking user to double click on this batch file to execute your app. What i did was to provide a JRE installation exe(eg: jre_1.7.0) with your app.
Now create a Batch file (install.bat) in which write following commands
jre_1.7.0 -> this will install jre on user's pc
set path="C\Program Files\Java\jre_1.7.0\bin"
java -jar yourAppName.jar
Why i installed JRE because different people have different JRE versions installed. So this makes it difficult to set path to the installed JRE's bin folder & calling the 'java -jar' command. Hence as you know which folders your JRE installation will create hence it is easy to set path and execute your jar file with 'java-jar' command.
Check that your jar file has the following structure (at least)
jarfile.jar
|---------- swong
|---------- Startup.class
|---------- META-INF
|---------- MANIFEST.MF
It seems like the class "Startup" is missing. Maybe your jar only contains the .java files, not the compiled classes.
This error message can be a mistakable java7 error, when you try to start java7 compiled classes with a different Java Runtime Environment then java7. Have you validated, that your .jar is started within a Java7 environment on those other test machines? Sometimes it happens, that you have installed different versions of JREs and you might not be sure which one is actually started.
To check which enviroment is used, you can check in your registry for the following value:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
this should point to your latest JRE. Or if you'd like to stay compatible to java6 as well, define the appropiate compile level in your build environment.

Run Java applications By double click

why i can`t run my java compiled applications with double click?
my applicatins just run in cmd (java -jar: my app.jar)
plz help me
You can make a batch file to run your command. This way it will work without the need to make associations to .jar files. If it is a windows app then start it with javaw.exe.
You need to associate the .jar extension with javaw.exe, then no console window will be shown, when you double click the jar file
This is usually done by the JDK/JRE installer, so either you didn't install the JDK properly, or you manually changed that associaten.
I think all the answer here are valid. But if you want a true executable file in Windows then you need to create a launcher. In windows, jar files are not executable. But exe files are. There are many tools out there than wrap all your java code around some native library. I recommend http://launch4j.sourceforge.net/ I think this is what you are looking for. You can easily create executable with icons and many more features.
You can create a Windows shortcut to your .jar file.
The following line could be the target of the Windows shortcut.
%windir%\system32\javaw.exe -Xms1m -Xmx1m -jar "C:\Program Files\Jar Directory\file.jar"
This has the advantage of allowing you to specify the javaw parameters that you want, as well as the Windows parameters (normal window, maximized, start in directory) that you want.
Just assign .jar files to be executed by javaw.exe. You can do that using the Open with dialog on a .jar file.
BTW, doesn't the Java installer do that for you?

Categories