Wednesday, 25 April 2012

Embedding a OpenJDK 7 Java JRE in Poker Copilot

As of an upcoming new OS X version, Apple's Java team are encouraging Java developers to embed a Java JRE in our applications. Unfortunately Java on the Mac is not quite ready for us to do this. Nevertheless I'm doing my best to prepare for this, so that I can give helpful feedback on problems to Oracle and Apple in time.

Here's how I currently got an embedded JRE into Poker Copilot:

1) I downloaded and installed Oracle JDK7u4 Mac OS X Port Developer Preview.

2) I copied the JRE folder from the developer preview. I copied from:

/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre

to 

a folder in my app I called ./jre

I launched my application using this command line: (note that this is in a dev environment not in a OS X app bundle, hence the hard-coded path to idea_rt.jar and my app classes not being jar'ed)

jre/bin/java -Dapple.laf.useScreenMenuBar=true "-Xdock:name=Poker Copilot" -Xdock:icon=../creative/512icn.png -Xmx768m -classpath "jre/lib/charsets.jar:jre/lib/jce.jar:jre/lib/jfr.jar:jre/lib/jfxrt.jar:jre/lib/JObjC.jar:jre/lib/jsse.jar:jre/lib/management-agent.jar:jre/lib/resources.jar:jre/lib/rt.jar:jre/lib/ext/dnsns.jar:jre/lib/ext/localedata.jar:jre/lib/ext/sunec.jar:jre/lib/ext/sunjce_provider.jar:jre/lib/ext/sunpkcs11.jar:jre/lib/ext/zipfs.jar:out/production/DesktopApp:lib/*:/Applications/IntelliJ IDEA 11.app/lib/idea_rt.jar" com.barbarysoftware.pokercopilot.Launcher

For clarity, here's same command line broken into separate lines:

jre/bin/java -Dapple.laf.useScreenMenuBar=true "-Xdock:name=Poker Copilot" -Xdock:icon=../creative/512icn.png -Xmx768m -classpath "jre/lib/charsets.jar:jre/lib/jce.jar:jre/lib/jfr.jar:jre/lib/jfxrt.jar:jre/lib/JObjC.jar:jre/lib/jsse.jar:jre/lib/management-agent.jar:jre/lib/resources.jar:jre/lib/rt.jar:jre/lib/ext/dnsns.jar:jre/lib/ext/localedata.jar:jre/lib/ext/sunec.jar:jre/lib/ext/sunjce_provider.jar:jre/lib/ext/sunpkcs11.jar:jre/lib/ext/zipfs.jar:out/production/DesktopApp:lib/*:/Applications/IntelliJ IDEA 11.app/lib/idea_rt.jar" com.barbarysoftware.pokercopilot.Launcher

3) It runs! There are a couple of rendering issues which are known by the Oracle/Apple team working on the OpenJDK7 Mac OS X Port. Namely, progress bars don't progress, unified toolbars don't unify, and window resizing is graphically not good. But otherwise, it runs!

For further clarity: this is the list of files in the embedded JRE I have on my class path:

jre/lib/charsets.jarjre/lib/jce.jarjre/lib/jfr.jarjre/lib/jfxrt.jarjre/lib/JObjC.jarjre/lib/jsse.jarjre/lib/management-agent.jarjre/lib/resources.jarjre/lib/rt.jarjre/lib/ext/dnsns.jarjre/lib/ext/localedata.jarjre/lib/ext/sunec.jarjre/lib/ext/sunjce_provider.jarjre/lib/ext/sunpkcs11.jarjre/lib/ext/zipfs.jar

Some are most likely not needed.

Now the big issue: the JRE is adding 55 MB to my app bundle size. That's after I zip the JRE folder. I need to determine which files I can safely remove from the JRE. But even then, the biggest file is the non-optional rt.jar, which compresses to 21 MB.

 

No comments:

Post a Comment