Upload
doankiet
View
222
Download
0
Embed Size (px)
Citation preview
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Modular Development with JDK 9
Alex BuckleyJava Platform Group, OracleOctober 2017
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 2
Process API UpdatesHTTP 2 ClientImprove Contended LockingUnified JVM LoggingCompiler ControlVariable HandlesSegmented Code CacheSmart Java Compilation, Phase TwoThe Modular JDKModular Source CodeElide Deprecation Warnings on Import StatementsResolve Lint and Doclint WarningsMilling Project CoinRemove GC Combinations Deprecated in JDK 8Tiered Attribution for javacProcess Import Statements CorrectlyAnnotations Pipeline 2.0Datagram Transport Layer Security (DTLS)Modular Run-Time ImagesSimplified Doclet APIjshell: The Java Shell (Read-Eval-Print Loop)New Version-String SchemeHTML5 JavadocJavadoc SearchUTF-8 Property FilesUnicode 7.0Add More Diagnostic CommandsCreate PKCS12 Keystores by DefaultRemove Launch-Time JRE Version Selection
Improve Secure Application PerformanceGenerate Run-Time Compiler Tests AutomaticallyTest Class-File Attributes Generated by javacParser API for NashornLinux/AArch64 PortMulti-Release JAR FilesRemove the JVM TI hprof AgentRemove the jhat ToolJava-Level JVM Compiler InterfaceTLS Application-Layer Protocol Negotiation ExtensionValidate JVM Command-Line Flag ArgumentsLeverage CPU Instructions for GHASH and RSACompile for Older Platform VersionsMake G1 the Default Garbage CollectorOCSP Stapling for TLSStore Interned Strings in CDS ArchivesMulti-Resolution ImagesUse CLDR Locale Data by DefaultPrepare JavaFX UI Controls & CSS APIs for ModularizationCompact StringsMerge Selected Xerces 2.11.0 Fixes into JAXPBeanInfo AnnotationsUpdate JavaFX/Media to Newer Version of GStreamerHarfBuzz Font-Layout EngineStack-Walking APIEncapsulate Most Internal APIsModule SystemTIFF Image I/OHiDPI Graphics on Windows and Linux
Platform Logging API and ServiceMarlin Graphics RendererMore Concurrency UpdatesUnicode 8.0XML CatalogsConvenience Factory Methods for CollectionsReserved Stack Areas for Critical SectionsUnified GC LoggingPlatform-Specific Desktop FeaturesDRBG-Based SecureRandom ImplementationsEnhanced Method HandlesModular Java Application PackagingDynamic Linking of Language-Defined Object ModelsEnhanced DeprecationAdditional Tests for Humongous Objects in G1Improve Test-Failure TroubleshootingIndify String ConcatenationHotSpot C++ Unit-Test Frameworkjlink: The Java LinkerEnable GTK 3 on LinuxNew HotSpot Build SystemSpin-Wait HintsSHA-3 Hash AlgorithmsDisable SHA-1 CertificatesDeprecate the Applet APIFilter Incoming Serialization DataImplement Selected ECMAScript 6 Features in NashornLinux/s390x Port
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 3
Modular Development with JDK 9
Java Language & JVM
Modular Applications
Modular Libraries
Modular JDK
Module-Aware Tools
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Modular Development with JDK 9
Part I: Programming In The Large
Part II: Migrating To Modules
Part III: The Modular JDK
4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Part I: Programming In The Large
5
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Programs are Classes Packages
7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 8
java.appletjava.awtjava.awt.colorjava.awt.datatransferjava.awt.dndjava.awt.eventjava.awt.fontjava.awt.geomjava.awt.imjava.awt.im.spijava.awt.imagejava.awt.image.renderablejava.awt.printjava.beansjava.beans.beancontextjava.iojava.langjava.lang.annotationjava.lang.instrumentjava.lang.invokejava.lang.managementjava.lang.refjava.lang.reflectjava.mathjava.netjava.niojava.nio.channelsjava.nio.channels.spijava.nio.charsetjava.nio.charset.spijava.nio.filejava.nio.file.attributejava.nio.file.spijava.rmijava.rmi.activationjava.rmi.dgcjava.rmi.registryjava.rmi.serverjava.securityjava.security.acljava.security.certjava.security.interfacesjava.security.specjava.sql
java.textjava.text.spijava.timejava.time.chronojava.time.formatjava.time.temporaljava.time.zonejava.utiljava.util.concurrentjava.util.concurrent.atomicjava.util.concurrent.locksjava.util.functionjava.util.jarjava.util.loggingjava.util.prefsjava.util.regexjava.util.spijava.util.streamjava.util.zipjavax.accessibilityjavax.activationjavax.activityjavax.annotationjavax.annotation.processingjavax.cryptojavax.crypto.interfacesjavax.crypto.specjavax.imageiojavax.imageio.eventjavax.imageio.metadatajavax.imageio.plugins.bmpjavax.imageio.plugins.jpegjavax.imageio.spijavax.imageio.streamjavax.jwsjavax.jws.soapjavax.lang.modeljavax.lang.model.elementjavax.lang.model.typejavax.lang.model.utiljavax.managementjavax.management.loadingjavax.management.modelmbeanjavax.management.monitor
javax.management.openmbeanjavax.management.relationjavax.management.remotejavax.management.remote.rmijavax.management.timerjavax.namingjavax.naming.directoryjavax.naming.eventjavax.naming.ldapjavax.naming.spijavax.netjavax.net.ssljavax.printjavax.print.attributejavax.print.attribute.standardjavax.print.eventjavax.rmijavax.rmi.CORBAjavax.rmi.ssljavax.scriptjavax.security.authjavax.security.auth.callbackjavax.security.auth.kerberosjavax.security.auth.loginjavax.security.auth.spijavax.security.auth.x500javax.security.certjavax.security.sasljavax.sound.midijavax.sound.midi.spijavax.sound.sampledjavax.sound.sampled.spijavax.sqljavax.sql.rowsetjavax.sql.rowset.serialjavax.sql.rowset.spijavax.swingjavax.swing.borderjavax.swing.colorchooserjavax.swing.eventjavax.swing.filechooserjavax.swing.plafjavax.swing.plaf.basicjavax.swing.plaf.metal
javax.swing.plaf.multijavax.swing.plaf.nimbusjavax.swing.plaf.synthjavax.swing.tablejavax.swing.textjavax.swing.text.htmljavax.swing.text.html.parserjavax.swing.text.rtfjavax.swing.treejavax.swing.undojavax.toolsjavax.transactionjavax.transaction.xajavax.xmljavax.xml.bindjavax.xml.bind.annotationjavax.xml.bind.annotation.adaptersjavax.xml.bind.attachmentjavax.xml.bind.helpersjavax.xml.bind.utiljavax.xml.cryptojavax.xml.crypto.domjavax.xml.crypto.dsigjavax.xml.crypto.dsig.domjavax.xml.crypto.dsig.keyinfojavax.xml.crypto.dsig.specjavax.xml.datatypejavax.xml.namespacejavax.xml.parsersjavax.xml.soapjavax.xml.streamjavax.xml.stream.eventsjavax.xml.stream.utiljavax.xml.transformjavax.xml.transform.domjavax.xml.transform.saxjavax.xml.transform.staxjavax.xml.transform.streamjavax.xml.validationjavax.xml.wsjavax.xml.ws.handlerjavax.xml.ws.handler.soapjavax.xml.ws.httpjavax.xml.ws.soap
javax.xml.ws.spijavax.xml.ws.spi.httpjavax.xml.ws.wsaddressingjavax.xml.xpathorg.ietf.jgssorg.omg.CORBAorg.omg.CORBA_2_3org.omg.CORBA_2_3.portableorg.omg.CORBA.DynAnyPackageorg.omg.CORBA.ORBPackageorg.omg.CORBA.portableorg.omg.CORBA.TypeCodePackageorg.omg.CosNamingorg.omg.CosNaming.NamingContextExtPackageorg.omg.CosNaming.NamingContextPackageorg.omg.Dynamicorg.omg.DynamicAnyorg.omg.DynamicAny.DynAnyFactoryPackageorg.omg.DynamicAny.DynAnyPackageorg.omg.IOPorg.omg.IOP.CodecFactoryPackageorg.omg.IOP.CodecPackageorg.omg.Messagingorg.omg.PortableInterceptororg.omg.PortableInterceptor.ORBInitInfoPackageorg.omg.PortableServerorg.omg.PortableServer.CurrentPackageorg.omg.PortableServer.POAManagerPackageorg.omg.PortableServer.POAPackageorg.omg.PortableServer.portableorg.omg.PortableServer.ServantLocatorPackageorg.omg.SendingContextorg.omg.stub.java.rmiorg.w3c.domorg.w3c.dom.bootstraporg.w3c.dom.eventsorg.w3c.dom.lsorg.w3c.dom.viewsorg.xml.saxorg.xml.sax.extorg.xml.sax.helpers
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 9
“A module is a set of packages designed for reuse.”
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Programs are Classes Packages Modules
10
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Introducing: java.base
11
java.base // module-info.java
module java.base {
exports java.lang;
exports java.io;
exports java.net;
exports java.util;
}
java.langjava.iojava.netjava.util
com.sun.crypto.providersun.nio.chsun.reflect.annotationsun.security.provider
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12
• public to everyone
• public but only to friend modules
• public only within a module
• protected
• package
• private
Accessibility (JDK 1 – JDK 8)
• public
• protected
• package
• private
Accessibility (JDK 9)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 13
// src/com/example/hello/SayHello.java
package com.example.hello;
import java.lang.*;
public class SayHello {
public static void main(String[] args) {
System.out.println(“Hello world”);
}
}
// src/module-info.java
module hello.world {
exports com.example.hello;
}
“Hello world” as a Module hello.world
com.example.hello
(No concealed packages)
javac –d classes –sourcepath src
module-info.java
com/example/hello/SayHello.java
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 14
// src/com/example/hello/SayHello.java
package com.example.hello;
import java.lang.*;
public class SayHello {
public static void main(String[] args) {
System.out.println(“Hello world”);
}
}
// src/module-info.java
module hello.world {
exports com.example.hello;
}
“Hello world” as a Module hello.world
com.example.hello
(No concealed packages)
javac –d classes –sourcepath src
module-info.java
com/example/hello/SayHello.java
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 15
Reusing a Module
hello.world
com.example.hello
(No concealed packages)
java.base
java.langjava.iojava.netjava.util
com.sun.crypto.providersun.nio.chsun.reflect.annotationsun.security.provider
// src/module-info.java
module hello.world {
exports com.example.hello;
requires java.base;
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 18
Reusing a Module
// src/module-info.java
module hello.world {
exports com.example.hello;
requires java.base;
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 19
“The unit of reuse is the unit of release.”
helloworld.jar
com/example/hello/SayHello.class
module-info.class
// src/module-info.java
module hello.world {
exports com.example.hello;
requires java.base;
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
modulepathSystem image
20
Running a Modular Application
java.base java.sql hello.world my.app spring guava
java -p mods -m hello.world
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 21
Running a Modular Application
java –p mods -m hello.world
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Running a Modular Application
• No missing dependencies
• No cyclic dependencies
• No split packages
22
java -p mods -m hello.world
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 23
common/hadoop-common-3.0.0-SNAPSHOT.jar:common/hadoop-nfs-3.0.0-SNAPSHOT.jar:common/lib/activation-1.1.jar:common/lib/apacheds-i\18n-2.0.0-M15.jar:common/lib/apacheds-kerberos-codec-2.0.0-M15.jar:common/lib/api-asn1-api-1.0.0-M20.jar:common/lib/api-util-1.0\.0-M20.jar:common/lib/asm-3.2.jar:common/lib/avro-1.7.4.jar:common/lib/commons-beanutils-1.7.0.jar:common/lib/commons-beanutils-\core-1.8.0.jar:common/lib/commons-cli-1.2.jar:common/lib/commons-codec-1.4.jar:common/lib/commons-collections-3.2.1.jar:common/l\ib/commons-compress-1.4.1.jar:common/lib/commons-configuration-1.6.jar:common/lib/commons-digester-1.8.jar:common/lib/commons-ht\tpclient-3.1.jar:common/lib/commons-io-2.4.jar:common/lib/commons-lang-2.6.jar:common/lib/commons-logging-1.1.3.jar:common/lib/c\ommons-math3-3.1.1.jar:common/lib/commons-net-3.1.jar:common/lib/curator-client-2.7.1.jar:common/lib/curator-framework-2.7.1.jar\:common/lib/curator-recipes-2.7.1.jar:common/lib/gson-2.2.4.jar:common/lib/guava-11.0.2.jar:common/lib/hadoop-annotations-3.0.0-\SNAPSHOT.jar:common/lib/hadoop-auth-3.0.0-SNAPSHOT.jar:common/lib/hamcrest-core-1.3.jar:common/lib/htrace-core4-4.0.1-incubating\.jar:common/lib/httpclient-4.2.5.jar:common/lib/httpcore-4.2.5.jar:common/lib/jackson-core-asl-1.9.13.jar:common/lib/jackson-jax\rs-1.9.13.jar:common/lib/jackson-mapper-asl-1.9.13.jar:common/lib/jackson-xc-1.9.13.jar:common/lib/java-xmlbuilder-0.4.jar:commo\n/lib/jaxb-api-2.2.2.jar:common/lib/jaxb-impl-2.2.3-1.jar:common/lib/jcip-annotations-1.0.jar:common/lib/jersey-core-1.9.jar:com\mon/lib/jersey-json-1.9.jar:common/lib/jersey-server-1.9.jar:common/lib/jets3t-0.9.0.jar:common/lib/jettison-1.1.jar:common/lib/\jetty-6.1.26.jar:common/lib/jetty-util-6.1.26.jar:common/lib/jsch-0.1.51.jar:common/lib/json-smart-1.1.1.jar:common/lib/jsp-api-\2.1.jar:common/lib/jsr305-3.0.0.jar:common/lib/junit-4.11.jar:common/lib/log4j-1.2.17.jar:common/lib/mockito-all-1.8.5.jar:commo\n/lib/netty-3.6.2.Final.jar:common/lib/nimbus-jose-jwt-3.9.jar:common/lib/paranamer-2.3.jar:common/lib/protobuf-java-2.5.0.jar:c\ommon/lib/servlet-api-2.5.jar:common/lib/slf4j-api-1.7.10.jar:common/lib/slf4j-log4j12-1.7.10.jar:common/lib/snappy-java-1.0.4.1\.jar:common/lib/stax-api-1.0-2.jar:common/lib/xmlenc-0.52.jar:common/lib/xz-1.0.jar:common/lib/zookeeper-3.4.6.jar:hdfs/hadoop-h\dfs-3.0.0-SNAPSHOT.jar:hdfs/hadoop-hdfs-nfs-3.0.0-SNAPSHOT.jar:hdfs/lib/commons-daemon-1.0.13.jar:hdfs/lib/hadoop-hdfs-client-3.\0.0-SNAPSHOT.jar:hdfs/lib/hpack-0.11.0.jar:hdfs/lib/leveldbjni-all-1.8.jar:hdfs/lib/netty-all-4.1.0.Beta5.jar:hdfs/lib/okhttp-2.\4.0.jar:hdfs/lib/okio-1.4.0.jar:hdfs/lib/xercesImpl-2.9.1.jar:mapreduce/hadoop-mapreduce-client-app-3.0.0-SNAPSHOT.jar:mapreduce\/hadoop-mapreduce-client-common-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-mapreduce-client-core-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-ma\preduce-client-hs-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-mapreduce-client-hs-plugins-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-mapreduce-\client-jobclient-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-mapreduce-client-nativetask-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-mapreduce-c\lient-shuffle-3.0.0-SNAPSHOT.jar:mapreduce/hadoop-mapreduce-examples-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-api-3.0.0-SNAPSHOT.jar:\yarn/hadoop-yarn-applications-distributedshell-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-applications-unmanaged-am-launcher-3.0.0-SNAP\SHOT.jar:yarn/hadoop-yarn-client-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-common-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-registry-3.0.0-S\NAPSHOT.jar:yarn/hadoop-yarn-server-applicationhistoryservice-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-server-common-3.0.0-SNAPSHOT.j\ar:yarn/hadoop-yarn-server-nodemanager-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-server-resourcemanager-3.0.0-SNAPSHOT.jar:yarn/hadoop\-yarn-server-sharedcachemanager-3.0.0-SNAPSHOT.jar:yarn/hadoop-yarn-server-web-proxy-3.0.0-SNAPSHOT.jar:yarn/lib/aopalliance-1.0\.jar:yarn/lib/commons-math-2.2.jar:yarn/lib/curator-test-2.7.1.jar:yarn/lib/fst-2.24.jar:yarn/lib/guice-3.0.jar:yarn/lib/guice-s\ervlet-3.0.jar:yarn/lib/javassist-3.18.1-GA.jar:yarn/lib/javax.inject-1.jar:yarn/lib/jersey-client-1.9.jar:yarn/lib/jersey-guice\-1.9.jar:yarn/lib/objenesis-2.1.jar
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Split packages in the real world
24
App.jar AppLib1.jar AppLib2.jar
package MyCommonPackage;
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 25
API.jarImpl1.jar
package P;
public interface Foo {…}
package P.Helper;
class X implements P.Foo {
… FooHelper.make() …
}
Impl2.jar
package P.Helper;
class Y implements P.Foo {
… FooHelper.make() …
}
package P.Helper;
class FooHelper {
P.Foo make() {…}
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 26
API.jarImpl1.jar
package P;
public interface Foo {…}
package P.Helper;
class X implements P.Foo {
… FooHelper.make() …
}
Impl2.jar
package P.Helper;
class Y implements P.Foo {
… FooHelper.make() …
}
package P.Helper;
class FooHelper {
P.Foo make() {…}
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 27
API.jarImpl1.jar
package P;
public interface Foo {…}
package P.Helper;
class X implements P.Foo {
… FooHelper.make() …
}
Impl2.jar
package P.Helper;
class Y implements P.Foo {
… FooHelper.make() …
}
package P.Helper;
class FooHelper {
P.Foo make() {…}
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 28
API.jarImpl1.jar
package P;
public interface Foo {…}
package P.Helper;
class X implements P.Foo {
… FooHelper.make() …
}
Impl2.jar
package P.Helper;
class Y implements P.Foo {
… FooHelper.make() …
}
package P.Helper;
class FooHelper {
P.Foo make() {…}
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 29
API.jarImpl1.jar
package P;
public interface Foo {…}
package P.Helper;
class X implements P.Foo {
… FooHelper.make() …
}
Impl2.jar
package P.Helper;
class Y implements P.Foo {
… FooHelper.make() …
}
package P.Helper;
class FooHelper {
P.Foo make() {…}
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Modular program structure
30
API.jar
Impl1.jar
Impl2.jar
requires
exports
requires
exports
module API {
exports P;
exports P.Helperto Impl1, Impl2;
}
package Q.Impl;
public class X implements P.Foo {
… P.Helper.FooHelper.make() …
}
package R.Impl;
public class Y implements P.Foo {
… P.Helper.FooHelper.make() …
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Summary of Part I: Programming In The Large
• A module is a set of packages designed for reuse.
• Modules offer strong encapsulation and reliable dependencies.
• Module-aware tooling is a big part of modular development.
31
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Part II: Migrating to Modules
32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 33
Typical application JAR JAR
JAR
JAR JAR
JARJAR
JAR
JARJAR JAR
JAR
JDK
JARJAR
JAR
JAR
JAR
JAR
JAR
JARJAR
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 34
Typical application
modulejava.base
modulejava.logging
modulejava.sql
modulejava.xml
JAR
JAR JAR
JARJAR
JAR
JARJAR JAR
JAR
JARJAR
JAR
JAR
JAR
JAR
JAR
JARJAR
JAR JAR
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 35
Sample scenario
jackson-databind-2.6.2.jar
myapp.jar
modulejava.base
modulejava.logging
mylib.jar
modulejava.xml
modulejava.sql
jackson-annotations-2.6.2.jar
jackson-core-2.6.2.jar
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 36
$ java -cp lib/myapp.jar:\
lib/mylib.jar:\
lib/jackson-core-2.6.2.jar:\
lib/jackson-databind-2.6.2.jar:\
lib/jackson-annotations-2.6.2.jar\
myapp.Main
Running the application
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 37
Migrating from the top down
jackson-databind-2.6.2.jar
modulemyapp
modulemylib
jackson-annotations-2.6.2.jar
jackson-core-2.6.2.jar
modulejava.base
modulejava.logging
modulejava.xml
modulejava.sql
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Migrating from the top down
• Module myapp
– Name: that’s easy
–What modules does it require?
–What packages does it export?
• Module mylib
– Name: that’s easy
–What modules does it require?
–What modules does it export?
38
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 39
$ jdeps -s lib/myapp.jar lib/mylib.jar
myapp.jar -> lib/jackson-core-2.6.2.jar
myapp.jar -> lib/jackson-databind-2.6.2.jar
myapp.jar -> mylib.jar
myapp.jar -> java.base
myapp.jar -> java.sql
mylib.jar -> java.base
Running jdeps
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 40
// src/mylib/module-info.java
module mylib {
exports com.myapp.util to myapp;
requires java.base;
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 41
// src/myapp/module-info.java
module myapp {
requires mylib;
requires java.base;
requires java.sql;
requires jackson.core; ???
requires jackson.databind; ???
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 42
If only …
jackson-databind-2.6.2.jar
jackson-core-2.6.2.jar
jackson-annotations-2.6.2.jar
modulejackson.core
modulejackson.databind
modulejackson.annotations
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 43
// src/myapp/module-info.java
module myapp {
requires mylib;
requires java.base;
requires java.sql;
requires jackson.core; ☺
requires jackson.databind; ☺
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 44
modulejackson.databind
modulemyapp
modulejava.base
modulejava.logging
modulemylib
modulejava.xml
modulejava.sql
modulejackson.annotations
modulejackson.core
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Automatic modules
• “Real” modules
• No changes to someone else’s JAR file :-)
• Module name derived from JAR file name (hyphens to dots, no version)
• Exports all its packages
• Requires all other modules
45
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 46
modulemyapp
modulemylib
modulejackson.databind
modulejackson.annotations
modulejackson.core
modulejava.xml
modulejava.sql
modulejava.logging
modulejava.base
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Summary of Part II: Migration to Modules
• Each application JAR is usually a good candidate to be a module.
• Each library JAR will modularize at its own pace.
• Automatic modules mean you’re not waiting for the weakest link.
47
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Migrating to JDK 9
• Java EE modules are deprecated for removal (use --add-modules)
51
java.activation
java.corba
java.transaction
java.xml.bind
java.xml.ws
java.xml.ws.annotation
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Migrating to JDK 9
• Java EE modules are deprecated for removal (use --add-modules)
• Illegal access to JDK internals causes runtime warnings (use --add-opens)
52
$ 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: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)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Migrating to JDK 9
• Java EE modules are deprecated for removal (use --add-modules)
• Illegal access to JDK internals causes runtime warnings (use --add-opens)
• Changes unrelated to modules
53
✓ Maven
✓ Gradle
✓ Eclipse
✓ IntelliJ
✓ Spring
✓ Hibernate
✓ ElasticSearch
✓ Hadoop
✓ JUnit
✓ ASM
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Summary of Part III: The Modular JDK
• “Modules all the way down.”
• JDK internals are accessible temporarily in JDK 9.
• You may need to upgrade tools and libraries to their JDK 9-aware versions.
54
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Summary of Summaries
• A module is a set of packages designed for reuse.
• Automatic modules assist with migration to modules.
• You may need to upgrade tools and libraries to their JDK 9-aware versions.
55
Java Language & JVM
Modular Applications
Modular Libraries
Modular JDK
Module-Aware Tools
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JDK 9 is here!
• http://jdk.java.net/9/
• Run jdeps –jdkinternals library.jar on JDK 8 or 9
• JEP 261: Module System
• JEP 260: Encapsulate Most Internal APIs
• JEP 223: New Version String Scheme
• JEP 220: Modular Run-Time Images
• JEP 200: The Modular JDK
57
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
58