Saturday, January 19, 2019

How to create a .jar association for your OpenJDK

From Java 11, Oracle has changed the license of their JDK, so you probably may want (or even have) to move to OpenJDK, and if you have moved already to OpenJDK, you may have noticed that clicking on a .jar didn't work anymore as it did with Oracle JDK binaries. This is because most of the pre-build OpenJDK binaries are coming without an installer on Microsoft Windows. Fortunately, it is easy to fix - with jarfix.

In the following example I show you how to use jarfix in order to setup the .jar association for your OpenJDK.


1. Download the OpenJDK

Download the OpenJDK from the source of your choice. You could get it from http://jdk.java.net/ or https://adoptopenjdk.net for example. Actually there are many more sources where you can get it, but I have downloaded the latest OpenJDK from https://adoptopenjdk.net, and extracted the .zip file to C:\Applications\jdk-11.0.1+13


2. Download jarfix

Download jarfix.exe from the jarfix homepage and store the .exe on a folder of your choice on your harddrive. On my Windows instance, I have stored the jarfix.exe to C:\Applications\jarfix\




3. Create a jarfix config file

Create a jarfix.ini file to C:\Applications\jarfix\ with the following content:

[jarfix]
options=/a
action="C:\Applications\jdk-11.0.1+13\bin\javaw.exe" -jar  "%1" %*


Those entries tell jarfix to setup a .jar association with the OpenJDK in C:\Applications\jdk-11.0.1+13\ - you may want to modify that path according to the actual path that you have choosen at step 1. The line called "options=/a" is optional, it tells jarfix to create a "Open as Administrator" menu entry in order to run .jar files also under the Admin account.

Hint: you can run jarfix /x in order to extract an example jarfix.ini file which has a lot of useful examples for a Java developer on Windows.

Update January 27, 2019: from Jarfix version 3 you can recreate hijacked .jar associations out of the box (by a double click without an .ini file) not only for the Oracle JDK, but also for the OpenJDK from Azul Systems.



4. Run jarfix using the config file

Open a Windows Command Prompt or simply hit both the Windows Key and R in order to enter the following command:

C:\Applications\jarfix\jarfix.exe /c


Update January 27, 2019: from Jarfix version 3 it is not necessary anymore to pass the option /c as a parameter. If a .ini file exists with the same name as the .exe in the same directory, jarfix will read the .ini file in order to initialize itself with the values from the .ini. In other words, you can simply double click on jarfix.exe and the content of jarfix.ini will be taken into account.








5. Test it

If you have run "jarfix /x" at step 3, you can double click on the existing jartest.jar in C:\Applications\jarfix in order to test whether it works as expected:




As you can see above we have launched the OpenJDK from AdoptOpenJDK by double-clicking on a .jar file.


1 comment:

  1. This is a good one, I though I'll go mad with these associations. Thank you so much for sharing this clever app.

    ReplyDelete