Freitag, 7. September 2018

MacOS deployment and ship Java Runtime JRE with Eclipse RCP product

This is not quite simple. Please follow the instructions to ship your RCP product with a JRE on MacOS.

Prerequisites


You need a working RCP product export with Maven Tycho to build a MacOS product.

1. Install Java Development Kit (JDK) on a MacOS system


Download the installation package from Oracle and install on a MacOS target system. You need a JDK. JRE is not sufficent. Dont't care about the size since we will delete everything but the JRE later on.

2. Copy the JDK to your product


The (for now) current JDK 1.8.181 is installed into that location:

/library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk

Open a shell and copy the JDK to your development project:
user@mac: cp -R /library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk /Users/peter/...


To uninstall the JDK you have just to delete the JDK directory:
user@mac: rm -rf /library/Java/JavaVirtualMachines/jdk1.8.0_181



Place the content of JDK-directory in the following directory of your exported RCP product:
YourProduct.app/Contents/Eclipse/jre


Open a shell and verify that the following command works properly:
user@mac: /path/to/YourProduct.app/Contents/Eclipse/jre/
     Contents/Home/jre/bin/java -version


3. Specify VM in product configuration


Modify the file YourProduct.ini and add the following 2 lines:

-vm
../Eclipse/jre/Contents/Home/jre/bin/java

The linebreak between -vm and the path is important!

Since the product is started from YourProduct.app/Contents/MacOS/YourProduct the path ../Eclipse/jre leads to the JDK we provided.

You can integrate the -vm option in your product build via the product configuration editor in tab Launch => launch arguments => macosx => programme arguments. Note that the linebreak is not needed there and is added by the build process.

4. Launch the product to test if everything works until now


Uninstall the JDK (rm -rf /library/Java/JavaVirualMachines/jdk1.8.0_181.jdk) and launch your RCP  product. If everything is correct it will use the JDK you provided. Otherwise it will fail to launch.

5. Remove unneeded files from JDK


You can remove a lot of files and directories from YourProduct.app/Contents/Eclipse/jre folder. You just need:

YourProduct.app/Contents/Eclipse/jre/Home/jre
YourProduct.app/Contents/Eclipse/jre/Info.plist

Remove all other files and directories. Your product will not start anymore but don't worry.

6. Fix Info.plist


The Info.plist contains the option CFBundleExecutable. The setting points to a symbolic link. This link gets broken in the deployment process.

The solution is to simply change CFBundleExecutable:

<key>CFBundleExecutable</key>
<string>../Contents/Home/jre/lib/jli/libjli.dylib</string>


7. Test and deploy


Launch the product to test that everything works as expected. Integrate the deployment of the JRE into your tycho build.

1 Kommentar: