The Diabolical Developer presents a pragmatic guide on running and compiling your application on Java 9. There are a lot of new resrtictions due to the Java 9 modular runtime, so make sure you read through carefully before your migration!
3. My Background
• Martijn Verburg (@karianna)
– CEO at jClarity
– Help run Adopt a JSR & Adopt OpenJDK programs
– Java Champion, Speaker, Author, Troublemaker
– aka "The Diabolical Developer"
• Adopt OpenJDK!
– Join us at https://www.adoptopenjdk.net
4. What I’ll cover
1. Downloading and Installing Java 9
2. Running your App(s)
3. Compiling your App(s)
4. Major Framework / JVM Language Support
5. GC and Other Performance Impacts
6. Jigsaw and Modules….
5. Downloading and Installing Java 9
• The Oracle Way
– http://www.oracle.com/technetwork/java/javase/
downloads/index.html
– Mac OS X, Windows, Linux x64 (RPM or tar ball)
• The Distro Way
– apt-get and / or yum openjdk9
• The AdoptOpenJDK Way
– https://www.adoptopenjdk.net
6. Running your App(s)
• NOT from within your IDE
• NOT from your build tool
• DO NOT try compiling code
• DO NOT worry about modularisation
• Look for JVM warnings
11. Flags that will kill your JVM
• -XX:+CMSIncrementalMode
• -Xincgc
• -XX:+UseCMSCompactAtFullCollection,
• -XX:+CMSFullGCsBeforeCompaction
• -XX:+UseCMSCollectionPassing.
12. Flags that will give JVM Warnings
• -XX:MaxPermSize=
• -XX:PermSize=
• -XX:+UseParNewGC
• -XX:+PrintGCDetails
• -XX:+PrintGC
13. Removed from Java 9
• JavaDB is gone!
– Get Apache Derby from https://db.apache.org/derby/
• hprof is gone!
– This is OK, you should be using jmap, jcmd
• jhat is gone!
• jvisualvm is gone!
– Get it from http://visualvm.github.io
14. Runtime Access Warnings
>java -jar jython-standalone-2.7.0.jar
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by jnr.posix.JavaLibCHelper (file:/C:/Jython/jython2.7.0/jython-
standalone-2.7.0.jar) to method sun.nio.ch.SelChImpl.getFD()
WARNING: Please consider reporting this to the maintainers of jnr.posix.JavaLibCHelper
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
15. Debugging Runtime Access
• —illegal-access=warn
• —illegal-access=debug
– Will give you the stacktrace
• —illegal-access=deny
– will give you future behaviour
16. —add-exports
• To use an internal API that has been made inaccessible
--add-exports, e.g.
--add-exports java.management/sun.management=ALL-UNNAMED
1. java.management is the source module name
2. sun.management is the package name
3. ALL-UNAMED are the target module(s)
17. —add-opens
• For deep reflection to access non-public members use:
—add-opens
• For example:
--add-opens java.management/sun.management=ALL-UNNAMED
Example allows all of the code on the class path to access nonpublic members
of public types in the java.management/sun.management package.
18. Java SE vs Java EE
• packages that are both in and out of JDK
– java.corba
– java.transaction
– java.activation
– java.xml.bind
– java.xml.ws
– java.xml.ws.annotation
• These are *not* part of the default modulepath
• These are @Deprecated for removal
– @Deprecated(since=“9”, forRemoval=true)
19. Java SE vs Java EE
• You can add the explicit module(s)
– —add-modules java.xml.bind
• Or deploy standalone version on the Classpath
– Just add the RI lib on your class path
• Or deploy standalone version on the module path
20. The move to CLDR Dates
• Unicode Common Library Date Repository
– Has subtly different behaviours if you’re not using
common locales
• Prepare for the move to 9
– java.locale.providers=JRE,CLDR
21. Check for library Compatibilities
https://wiki.openjdk.java.net/display/quality/Quality+Outreach
22. Compiling your App
• Underscores are verboten, e.g.
static Object _ = new Object();
• -source, -target and -release
– Supports a policy of 3 back
– i.e. You can’t generate Java 5 byte code
– Try to use the new -release
• Use jdeps
– Warning, its a static analysis tool only
23. Compile Access Warnings
error: package com.sun.java.swing.plaf.nimbus is not visible
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
^
(package com.sun.java.swing.plaf.nimbus is declared
in module java.desktop, which does not export it)
1 error
25. jdeprscan
• jdeprscan commons-math3-3.6.1.jar
• This command produces several lines of output.
For example, one line of output might be:
class org/apache/commons/math3/util/MathUtils uses
deprecated method java/lang/Double::<init>(D)V
27. IDEs
• IntelliJ
– Latest version works perfectly
• Eclipse
– Latest version will work on Oct 11th
• Netbeans
– Latest development (9.0 beta) version works well
• vi
– What do you think!
30. Eclipse Oxygen.1
• In eclipse.ini after —launcher.appendVmargs add:
-vm C:Program FilesJavajdk-9binjavaw.exe
• In eclipse.ini add:
—add-modules=ALL-SYSTEM
• Then install JDT 9 support:
https://marketplace.eclipse.org/content/java-9-support-oxygen/
• Then add Java 9 via
– Preferences —> Java —> Installed JREs
31. Build Tools
• Maven
• Gradle
• Ant (Yes, it’s still a thing)
• Shell Script / Custom
32. Maven 3.5.0
• You must update all of your plugins explicitly
• https://cwiki.apache.org/confluence/display/MAVEN/Java+9+-+Jigsaw
• Plugins that still don’t work:
– Animal Sniffer
– Site (because of the version string change…)
• Does not have first class support for creating modules
33. Gradle 4.2
• Gradle must start on a Java 9 JDK
gradle -version
• In your build.gradle file:
sourceCompatibility = 9
targetCompatibility = 9
• Does not have first class support for
creating modules
35. Multi Release JAR files
• jar --create --file MR.jar -C sampleproject-base
demo --release 9 -C sampleproject-9 demo
- demo
- SampleClass.class
- META-INF
- versions
- 9
- demo
- SampleClass.class
• Java 9 version will override the earlier version
– If the same class name
38. Major Library Support
• Apache Commons X - Mostly ❌
• Log4J - ✅
• Hibernate - ✅
• Jackson - ✅
• JUnit and Jacoco - ✅
– JUnit 5 and Jacob 0.7.9
39. Major Tooling Support
• jClarity’s Censum and Illuminate - ✅
– Well very soon
• ZeroTurnaround JRebel - ✅
– Even supports module reloading
40. Major Web / App Server Support
• Tomcat - ❌
– 9.0.0 will fix this
• Glassfish - ❌
– 5.0.1 will fix this
• Jboss / Wildfly - ❌
– 11.0 will fix this
• Oracle’s Weblogic - ❌
• IBM’s Websphere / Liberty - ❌
41. GC and Other Performance Issues
• Default GC is now G1
– It’s a pause time collector
– Your app will have difference perf characteristics
– Your app will now take more memory
• New Logging
-Xlog[:[what][:[output][:[decorators][:output-options [,...]]]]]
• www.jclarity.com/censum
– See what I did there!
42. Compact Strings
• If all the characters of the String can be
represented using a byte — LATIN-1
– A byte array will be used internally
– Such that one byte is given for one character.
• In other cases, if any character requires
more than 8-bits to represent it
– All the characters are stored using two bytes for
each — UTF-16 representation.
44. It’s too early!!!
• The library ecosystem needs to migrate first
• The IDEs need to give better support
– IntelliJ is pretty good already
• The Build tools need to give better support