Using packr to bundle an OS X JRE, from linux

(by Eron Gjoni, rufsketch1#gmail.com)
packr is a useful little program that allows you to include a copy of the JRE along with your runnable JAR file. Making it much easier for your users to just download and run your program, without them having to worry about java versions or installation procedures. You can learn to use packr from the documentations available on its github page
https://github.com/libgdx/packr
Notably, however, packr requires platform specific copies of the JDK in order to bundle a JRE with your program. This is fine if you have easy access to each of the platforms you wish to support, or if you intend to use openJDK. But what do you do if you only have linux, but want to create a self contained runnable for OS X users? Oracle only provides the OSX JDK as a dmg. Luckily, we can still access the files we need!
Download a copy of the Java SE JDK for OS X from Oracle.
use 7zip to extract the contents of the .dmg.

7z x jdx-[version number]-x64.dmg -oosxJDK

cd into the osxJDK subdirectory created by the command above.
You’ll see a number of files that were extracted from the dmg.
We’re interested in the contents of the file ending in .hfs.
To access its contents, first make sure you have the hfsplus module active.

sudo modprobe hfsplus

Then, create a subdirectory into which to mount the .hfs file.

mkdir mountedHFS

Then, mount the file

mount -oloop 4.hfs mountedHFS

If you cd into the mountedHFS directory, you will find a .pkg file. Move it to the parent directory and then unmount the .hfs file.

sudo mv JDK\ 8\ Update\ 131.pkg ../ && cd ../ && sudo umount mountedHFS

Next, extract the contents of the .pkg file into a new subdirectory.

7z x JDK\ 8\ Update\ 131.pkg -opkg

cd into that subdirectory

cd pkg

You will find a number of files and subdirectories. cd into the jdk180131.pkg subdirectory (replacing the version number as appropriate)

cd jdk180131.pkg

There you will find a file named Payload. We will need to extract the contents of this file using

cat Payload | gunzip -dc |cpio -i

A new subdirectory called Contents will be created. if you cd into Contents/Home you will find the files needed by packr to create a self-contained bundle for OSX.

Leave a Reply