Jigsaw
A long winding road started almost 8
years ago...
About the speakers
Rikard Thulin Fredrik Jansson
History: It started with a war
jar cvf jigsaw.war
SUN Oracle OSGi
Obvious solution
Apply a well know pattern!
SUN Oracle OSGi
We lost a few years… But now, close to eight years later we are on track!
Jigsaw motivation
● avoid JAR/Classpath Hell
● Encapsulation across packages
● Remove manual security
● Faster startup
JSR 376: JavaTM
Platform Module System
Spec lead: Mark Reinhold - Chief Architect of the Java Platform group at Oracle.
Java 7 dependency graph
Java 9 dependency graph by modules
The spaghetti monster and cyclic dependencies
We have been warned since 1996 of sun packages
sun internal API:s
deprecated in JDK 9
planned to be removed in JDK10
workaround with command line flag
An application that uses only standard Java SE APIs, and possibly also JDK-
specific APIs, must work the same way […] as it does today. [1]
To find problems, use the Java Dependency Analysis Tool (jdeps -jdkinternals)
[1] Project Jigsaw: Goals & Requirements
Binary structure of JRE/JDK 9
● Disruptive change
● Be warned if you
○ Written your own class loader
○ Do things with rt.jar or tools.jar
○ Use the endorsed mechanism
○ Using the extension mechanism
○ Jar URL Schema
■ jar:file:<path-to-jar>!<path-to-file-in-jar>
■ jrt:/<module-name>/<path-to-file-in-module>
Binary structure of JRE/JDK 9
● Mostly affect tools vendors
○ Has been in JDK 9 builds since late 2014
● Good change, as the previous approach was as-is-works
● Need more details? - google JEP 261
Version-string schema
● Will change, but is not in JDK 9 builds yet
if (System.getProperty(“java.version”).startsWith(“1.7”)) {
System.out.println(“This will not work…”);
}
Modules
The file module-info.java contains the modules definition
module-info.java:
module com.squeed.javaforum {
}
Dependencies
module com.squeed.javaforum {
requires com.squeed.nforum;
requires java.logging;
}
All modules depends on java.base
Encapsulation
module com.squeed.javaforum {
exports com.squeed.javaforum.agenda;
exports com.squeed.javaforum.party to somemodule;
}
Second export is a qualified export
Encapsulation
public
protected
<package>
private
Encapsulation
public to everyone
public to specific modules
public within a module
public
protected
<package>
private
Reflection
setAccessible(true)
Is enforced by the compiler, VM and core reflection
Is enforced by the compiler, VM and core reflection
Classloaders are unchanged
Compared to today's module systems like OSGi - “classloaders on steroids”
Image by Alex Buckley
Jigsaw vs OSGi
Summary
● Start now
○ If you build heavy stuff (IDE’s, build tools, application servers)
● Wait a year for the Java 9 release
○ If you build vanilla (aka. “regular”)
● Safe harbor - do not wait too long
○ Dependencies to 3PP may cause problems
Java 9 might change a lot of stuff
● How maven / IDEs / application servers works
Q & A(maybe)

Jigsaw - Javaforum 2015Q4

  • 1.
    Jigsaw A long windingroad started almost 8 years ago...
  • 2.
    About the speakers RikardThulin Fredrik Jansson
  • 3.
    History: It startedwith a war jar cvf jigsaw.war SUN Oracle OSGi
  • 4.
    Obvious solution Apply awell know pattern! SUN Oracle OSGi
  • 5.
    We lost afew years… But now, close to eight years later we are on track!
  • 6.
    Jigsaw motivation ● avoidJAR/Classpath Hell ● Encapsulation across packages ● Remove manual security ● Faster startup JSR 376: JavaTM Platform Module System Spec lead: Mark Reinhold - Chief Architect of the Java Platform group at Oracle.
  • 7.
  • 8.
    Java 9 dependencygraph by modules
  • 9.
    The spaghetti monsterand cyclic dependencies
  • 10.
    We have beenwarned since 1996 of sun packages
  • 11.
    sun internal API:s deprecatedin JDK 9 planned to be removed in JDK10 workaround with command line flag An application that uses only standard Java SE APIs, and possibly also JDK- specific APIs, must work the same way […] as it does today. [1] To find problems, use the Java Dependency Analysis Tool (jdeps -jdkinternals) [1] Project Jigsaw: Goals & Requirements
  • 12.
    Binary structure ofJRE/JDK 9 ● Disruptive change ● Be warned if you ○ Written your own class loader ○ Do things with rt.jar or tools.jar ○ Use the endorsed mechanism ○ Using the extension mechanism ○ Jar URL Schema ■ jar:file:<path-to-jar>!<path-to-file-in-jar> ■ jrt:/<module-name>/<path-to-file-in-module>
  • 13.
    Binary structure ofJRE/JDK 9 ● Mostly affect tools vendors ○ Has been in JDK 9 builds since late 2014 ● Good change, as the previous approach was as-is-works ● Need more details? - google JEP 261
  • 14.
    Version-string schema ● Willchange, but is not in JDK 9 builds yet if (System.getProperty(“java.version”).startsWith(“1.7”)) { System.out.println(“This will not work…”); }
  • 15.
    Modules The file module-info.javacontains the modules definition module-info.java: module com.squeed.javaforum { }
  • 16.
    Dependencies module com.squeed.javaforum { requirescom.squeed.nforum; requires java.logging; } All modules depends on java.base
  • 17.
    Encapsulation module com.squeed.javaforum { exportscom.squeed.javaforum.agenda; exports com.squeed.javaforum.party to somemodule; } Second export is a qualified export
  • 18.
  • 19.
    Encapsulation public to everyone publicto specific modules public within a module public protected <package> private
  • 20.
    Reflection setAccessible(true) Is enforced bythe compiler, VM and core reflection
  • 21.
    Is enforced bythe compiler, VM and core reflection Classloaders are unchanged Compared to today's module systems like OSGi - “classloaders on steroids” Image by Alex Buckley Jigsaw vs OSGi
  • 22.
    Summary ● Start now ○If you build heavy stuff (IDE’s, build tools, application servers) ● Wait a year for the Java 9 release ○ If you build vanilla (aka. “regular”) ● Safe harbor - do not wait too long ○ Dependencies to 3PP may cause problems Java 9 might change a lot of stuff ● How maven / IDEs / application servers works
  • 23.