Update: Note that as of October 11/2017, Java 9 is 100% supported “out of the box” by Eclipse IDE, Oxygen Edition; Java 9 can be used to run your Eclipse IDE, Oxygen Edition, and can be used to build Java 9 applications without additional configuration. Download or update today.
I’ve started tinkering with the creation of custom Java binary runtime image files. An image file is a configuration of modules packaged up as a runtime platform. The default image contains, basically, everything that makes up the Java runtime. A custom image can contain some subset of that.
I created, for example, an image that includes only the “compact 3” profile, configured a JRE in the Eclipse preferences and specified it as the JRE System Library on a Java project. Eclipse Neon handles the custom profile exactly as expected.
Note the abridged list of modules under the JRE System Library in the project, and the somewhat simpler Module Dependencies view (as compared to the similar but somewhat more disturbing view for all modules).
Creating a custom image is easy. Just use the jlink command in the Java 9 + Jigsaw builds. I used the command as below, to create a custom image that contains just what I need to run Eclipse.
$ bin/jlink --modulepath jmods/ --addmods java.desktop,java.logging,java.sql --output /home/java9/runtimes/desktop
This creates directory named desktop that contains everything needed to run the defined subset of Java (i.e. the
java.sql modules). I’m a little disappointed that Eclipse requires the
java.desktop module; I had hoped that I might get away without including Swing and AWT in the image, but there are at least a small number of references to AWT classes in the Eclipse Platform and to include them I need to pull in the entire desktop module.
I’m probably missing a module, since I haven’t poked in all of the corners in all of the Eclipse features yet. I got this far by resolving the
ClassNotFoundExceptions as I encountered them. Eclipse will be more helpful at identifying missing modules if pull in the source code. The jdeps utility may also be helpful.
Note that in order to debug, you need to add the
jdk.jdwp.agent module in the image so that the debugger can actually connect to the runtime.
The resulting image file (~40MB) is about 30% of the size of the full JDK image (~140MB) and 60% of the size of a Java SE image file (~67MB). The runtime binaries and resources are more-or-less the same size for every configuration (~180MB on my Fedora 22 system), but there are some differences depending on the modules that are included: my
desktop configuration includes some libraries and fonts that are not included in the
compact3 configuration, for example.
I’m not quite sure what this means yet with regard to running Eclipse on custom Java 9 images, but it’s certainly clear that with this early beta of Java 9 support for Eclipse Neon, the Eclipse IDE already does a pretty good job of helping you write plain-old-Java applications using Java 9.
Note that I’m a couple of builds behind on JDK 9 + Jigsaw, so my file size numbers may be a bit bogus. I’ll update to the latest and greatest for my next instalment.
You can probably get the size down a bit with more advanced options like `–compress-resources on` and `–exclude-files *.diz`.
Pingback: Modularity in Java? Don’t Wait For Java 9/Jigsaw – Eclipse for Embedded and Scientific Tools