Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

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.


Sunday, May 7, 2017

Solaris' pargs, penv, pfiles, pmap, and pstack on GNU/Linux

I really like the p-commands on Sun/Oracle Solaris and I miss those on GNU/Linux. Therefore I have gathered/created rudimental equivalent one-liners that work on a PID.

I have added the following functions to my ~/.bash_aliases file that is being sourced by my ~/.bashrc. pargs, penv, and pmap are gathering the proc file system, while pfiles and pstack are calling lsof resp. gdb.

function pargs() { cat /proc/$1/cmdline | tr '\0' ' ' | sed 's/ $/\n/g'; }
function penv() { cat /proc/$1/environ | tr '\0' '\n'; }
function pfiles() { lsof -p $1; }

function pmap() { cat /proc/$1/maps; }
function pstack() { sudo gdb --pid=$1 --batch -ex "thread apply all bt"; }


Note that due to a kernel hardening (ptrace protection) on Ubuntu 10.10 and later you need to call gdb under the control of sudo, or alternatively modify the ptrace_scope property. See also https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection and https://askubuntu.com/questions/41629/after-upgrade-gdb-wont-attach-to-process


Friday, February 10, 2017

How the NumericalChameleon Installer obtains the latest JRE for Windows

Today I will explain how the NumericalChameleon installer obtains the latest Java Runtime Environment (JRE) for Microsoft Windows.

The NumericalChameleon (http://numericalchameleon.net) is written in Java and it relies on a JRE that is installed on your system. The NumericalChameleon installer checks at first whether a JRE is installed. If there is one, everything is fine and the installer will continue with a normal installation. If there is none, the installer downloads the latest JRE offline installer from Oracle and launches it. The offline installer installs the JRE on your system and once it is installed, it will give back the control to the NumericalChameleon installer that continues with the installation until the NumericalChameleon software package is installed as well.

Below you find a screenshot of the NumericalChameleon installer, localized in German, running on Windows 10 x64 while downloading the latest JRE offline installer:



Since the actual locations of the JRE offline exe installers are different for each Java version, and those locations are both unpredictable and volatile, it is important for the NumericalChameleon installer to rely on well known static URIs, because the installer binary cannot be changed/patched anymore once it is deployed on the web.

Those well known URIs are redirects in the .htaccess file on my Apache server actually, and the redirects are being updated every day. I create those redirects by parsing the website that has the locations of the Windows JRE offline installers.

$ cat bin/update_htaccess
#!/bin/bash
HTACCESS="$HOME/numericalchameleon/.htaccess"
STATIC="$HOME/numericalchameleon/.htaccess.static"

cat $STATIC > $HTACCESS

# the locations of the JRE offline installers
URL="https://www.java.com/en/download/manual.jsp"
CONTENT=$(curl -s "$URL")

IDENTIFIER="Windows Offline</a>"
if [[ "$CONTENT" =~ BundleId=([^\"]+)\"\>[[:space:]]*"$IDENTIFIER" ]]; then
    printf "Redirect /get_java_win32bit http://javadl.oracle.com/webapps/download/AutoDL?BundleId=%s\n" ${BASH_REMATCH[1]} >> $HTACCESS
fi

IDENTIFIER="Windows Offline (64-bit)</a>"
if [[ "$CONTENT" =~ BundleId=([^\"]+)\"\>[[:space:]]*"$IDENTIFIER" ]]; then
    printf "Redirect /get_java_win64bit http://javadl.oracle.com/webapps/download/AutoDL?BundleId=%s\n" ${BASH_REMATCH[1]} >> $HTACCESS
fi

The .htaccess.static file just contains entries that never change. The update_htaccess script runs by cron periodically on the server in order to have entries that are up to date.

$ crontab -l | tail -1

9 3 * * * cd bin; ./update_htaccess

After the cron was running, updated redirects can be found in the .htaccess file. In the example below the redirects are from Java 8u121:

$ tail -2 .htaccess

Redirect /get_java_win32bit http://javadl.oracle.com/webapps/download/AutoDL?BundleId=218831_e9e7ea248e2c4826b92b3f075a80e441
Redirect /get_java_win64bit http://javadl.oracle.com/webapps/download/AutoDL?BundleId=218833_e9e7ea248e2c4826b92b3f075a80e441

The installer can now rely on the fixed addresses below, dependent whether a 32 bit or a 64 bit system has been found:
Now you know how the NumericalChameleon installer gets the latest JRE on Windows.

Hint: if the approach above should ever fail and the redirects are not being created, the current installer will fail with a 404. In that case you can simply install the JRE manually before you start the NumericalChameleon installer. In that case the installer won't even go to the internet, because the condition is met already that a JRE has to be installed.