Modularity in Java 9
Balázs LájerSoftware Architect, GE HealthCare
HOUG – Oracle Java conference, 04. Apr. 2016.
MANIFEST.MF
3
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Osgi-example
Bundle-SymbolicName: osgi-example
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: osgi_example.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.osgi.framework;version="1.3.0"
Export-Package: osgi.example.api
Bundle-ActivationPolicy: lazy
MANIFEST.MF
4
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Osgi-example
Bundle-SymbolicName: osgi-example
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: osgi_example.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.osgi.framework;version="1.3.0"
Export-Package: osgi.example.api
Bundle-ActivationPolicy: lazy
Modularity in Java - OSGi
5
OSGi Container
Class loading
Bundle Av1.0.0
Bundle Av1.1.0
Bundle Bv2.0.0
Bundle Bv1.0.0
Bundle Cv1.1.0
Services
Service Registry
Life Cycle
Modularity in Java – OSGi
6
OSGi: modularity on top of the Java platform
Source: https://www.osgi.org/developer/architecture/
Modularity of the platform – Java 9 (Project Jigsaw)
7Source: http://blog.takipi.com/java-9-the-ultimate-feature-list/
Modularity of the platform – Java 9 (Project Jigsaw)
8
The JDK is monolithic (JDK 7b65)
Source: http://openjdk.java.net/projects/jigsaw/doc/jdk-modularization.html
Modularity of the platform – Java 9 (Project Jigsaw)
9
Classpath Hell
3 questions:
• Is anything missing?
• Are there any conflicts?
• Is it safe to change a private API?
Source: https://www.oracle.com/javaone/on-demand/index.html
Modularity of the platform – Java 9 (Project Jigsaw)
10
Module declaration: module-info.java module com.foo.bar {requires org.baz.qux;exports com.foo.bar.alpha;exports com.foo.bar.beta;
}
Module artifacts: modularized jar files – JMOD?
Module descriptor: module-info.class
Module path
Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Modularity of the platform – Java 9 (Project Jigsaw)
11
Platform modules
module java.base {exports java.io;exports java.lang;exports java.lang.annotation;exports java.lang.invoke;exports java.lang.module;exports java.lang.ref;exports java.lang.reflect;exports java.math;exports java.net;...
}
http://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.html
Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Modularity of the platform – Java 9 (Project Jigsaw)
12
module com.foo.bar {requires org.baz.qux;exports com.foo.bar.alpha;exports com.foo.bar.beta;
}
Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Modularity of the platform – Java 9 (Project Jigsaw)
13
module java.sql {requires public java.logging;requires public java.xml;exports java.sql;exports javax.sql;exports javax.transaction.xa;
}
Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Migration to Java 9: automatic modules
15Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Migration to Java 9: automatic modules
16Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Modularity of the platform – Java 9 (Project Jigsaw)
17
Services
module java.sql {requires public java.logging;requires public java.xml;exports java.sql;exports javax.sql;exports javax.transaction.xa;uses java.sql.Driver;
}
module com.mysql.jdbc {requires java.sql;requires org.slf4j;exports com.mysql.jdbc;provides java.sql.Driver with com.mysql.jdbc.Driver;
}Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
OSGi and Java 9
18
Java 9
module descriptor
static servicesmodularized platform
modularized JARs
OSGibundle lifecycle
class loading / bundledynamic servies
OSGi container
bundle descriptors (Manifest)
Class loading
Modularity of the platform – Java 9 (Project Jigsaw)
20
Private / Internal APIs banned
sun.misc.Unsafe
The three most important rules of modularity are: Hide, Hide, and Hide.(Peter Kriens, http://blog.osgi.org/2011/05/what-you-should-know-about-class.html)
Source: http://openjdk.java.net/projects/jigsaw/spec/sotms/
Modularity of the platform – Java 9 (Project Jigsaw)
21
Proposal:
“- If it has a supported replacement in JDK 8 then we will encapsulateit in JDK 9;
Source:http://mail.openjdk.java.net/pipermail/jigsaw-dev/2015-August/004433.html
- If it does not have a supported replacement in JDK 8 then we will notencapsulate it in JDK 9, so that it remains accessible to outsidecode; and, further,
- If it has a supported replacement in JDK 9 then we will deprecate itin JDK 9 and encapsulate it, or possibly even remove it, in JDK 10.”
Java 9 (Project Jigsaw)
22
JEP 200: The modular JDK
JEP 201: Modular source code
JEP 220: Modular run-time images
JEP 260: Encapsulate most internal APIs
JEP 261 / JSR 376: Java Platform Module System
Source:https://www.oracle.com/javaone/on-demand/index.html
Sources
23
http://openjdk.java.net/projects/jigsaw/spec/sotms/http://www.slideshare.net/martintoshev/modularity-of-the-java-platform-osgi-jigsaw-and-penrosehttps://www.osgi.org/developer/architecture/http://openjdk.java.net/projects/jigsaw/doc/jdk-modularization.htmlhttp://openjdk.java.net/projects/jigsaw/quick-starthttp://www.slideshare.net/SanderMak/java-modularity-life-after-java-9https://blogs.oracle.com/jtc/entry/a_first_look_at_compacthttp://njbartlett.name/2015/11/13/osgi-jigsaw.htmlhttp://www.javaworld.com/article/2878952/java-platform/modularity-in-java-9.htmlhttps://www.oracle.com/javaone/on-demand/index.htmlhttp://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.htmlhttp://mail.openjdk.java.net/pipermail/jigsaw-dev/2015-August/004433.htmlhttp://blog.osgi.org/2011/05/what-you-should-know-about-class.htmlhttp://blog.takipi.com/java-9-the-ultimate-feature-list/http://openjdk.java.net/jeps/261