An overview ofProject Jigsaw
src/main/java
api/Foo.java
internal/Qux.java
<project> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>foo</artifactId> <version>1</version> </project>
<project> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>bar</artifactId> <version>1</version> </project>
src/main/java
api/Bar.java
internal/Baz.java
pom.xml pom.xml
<project> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>bar</artifactId> <version>1</version> <dependencies> <dependency> <groupId>example</groupId> <artifactId>foo</artifactId> <version>1</version> </dependency> </dependencies> </project>
module-info.java example.foo
api/Foo.java
internal/Qux.java
module-info.java example.bar
api/Bar.java
internal/Baz.java
module example.foo { exports api; }
module example.bar { requires example.foo; }
Scope
Task module descriptor
module descriptordeployment descriptorbuild execution descriptorAPI for custom tasks
runtimecompile-time build-time
Enforcement obligatory (with opt-out)
optional(provided/optional dependency)
Unit Java package (sub-)project
api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
class path (system class loader)
Modularity prior to Java 9 is emulated by class loader hierarchies. By tweaking classloaders to define multiple parents, it is also possible to run several versions of thesame module (e.g. OSGi).
api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
module loader
example.foo
exam
ple.
bar
“example.bar reads example.foo”
The integrity of the module graph is verified by the Java 9 runtime. Jars without amodule-info.class are bundled in an unnamed module that reads all modules (fallback).
try { Class<?> pluginType = Class.forName("example.Foo"); runAppWithPlugin(pluginType); } catch(ClassNotFoundException exception) { runAppWithoutPlugin(); }
void runAppWithPlugin(Class<?> pluginType) { activate(pluginType.newInstance()); // and run the app... }
When code is bundled as a module, looking up a class is still possible but any execution of foreign code is no longer permitted.
In order to overcome this, a new reflection API for modules is introduced that allowsfor the dynamic attachment of “read edges” at runtime. At compile time, the currentdraft does however not foresee a possibility of defining optional dependencies.
module example.overview {
exports pkg.name; exports pkg.other.name to example.friend, example.other;
requires mdl.name; requires public mdl.name.exposed;
provides service.type.name with service.impl.name; uses service.other.type.name;}
Jigsaw recommends crossing of module boundaries by using service interfaces.Implementations of such interfaces can then be retreived by the ServiceLoader API.
Finally, modules can – similarly to class loaders – be organized in layers. This allowsThe migration of class loader hierarchy systems into a modularized formats. Layerscan be created programmatically via a reflection API.
Java 9: more than Jigsaw! (biased selection)
• New process API• HTTP2 client• Improved contended locking• Unified JVM logging• Compiler control• Variable handles• Segmented code cache• Smart Java compilation, phase 2• Project Coin extensions
(private interface methods)• Unicode 7.0/8.0• Convenience collection factories
• Annotation pipeline enhancements• Multi-version jar files• Compact strings• “Indifying” string concatenation• Stack-walking API• Currency and money API• Enhanced method handles• Platform specific desktop features• javac performance (sjavac, type inference)• Jshell• javadoc improvements (HTML5, search)• Improved concurrency
http://rafael.codes@rafaelcodes
http://documents4j.comhttps://github.com/documents4j/documents4j
http://bytebuddy.nethttps://github.com/raphw/byte-buddy
Top Related