Jigsaw - Javaforum 2015Q4

23
Jigsaw A long winding road started almost 8 years ago...

Transcript of Jigsaw - Javaforum 2015Q4

Page 1: Jigsaw - Javaforum 2015Q4

JigsawA long winding road started almost 8

years ago...

Page 2: Jigsaw - Javaforum 2015Q4

About the speakers

Rikard Thulin Fredrik Jansson

Page 3: Jigsaw - Javaforum 2015Q4

History: It started with a warjar cvf jigsaw.war

SUN Oracle OSGi

Page 4: Jigsaw - Javaforum 2015Q4

Obvious solutionApply a well know pattern!

SUN Oracle OSGi

Page 5: Jigsaw - Javaforum 2015Q4

We lost a few years… But now, close to eight years later we are on track!

Page 6: Jigsaw - Javaforum 2015Q4

Jigsaw motivation● avoid JAR/Classpath Hell● Encapsulation across packages● Remove manual security● Faster startup

JSR 376: JavaTM Platform Module SystemSpec lead: Mark Reinhold - Chief Architect of the Java Platform group at Oracle.

Page 7: Jigsaw - Javaforum 2015Q4

Java 7 dependency graph

Page 8: Jigsaw - Javaforum 2015Q4

Java 9 dependency graph by modules

Page 9: Jigsaw - Javaforum 2015Q4

The spaghetti monster and cyclic dependencies

Page 10: Jigsaw - Javaforum 2015Q4

We have been warned since 1996 of sun packages

Page 11: Jigsaw - Javaforum 2015Q4

sun internal API:sdeprecated 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

Page 12: Jigsaw - Javaforum 2015Q4

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>

Page 13: Jigsaw - Javaforum 2015Q4

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

Page 14: Jigsaw - Javaforum 2015Q4

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…”);

}

Page 15: Jigsaw - Javaforum 2015Q4

ModulesThe file module-info.java contains the modules definition

module-info.java:

module com.squeed.javaforum {}

Page 16: Jigsaw - Javaforum 2015Q4

Dependencies

module com.squeed.javaforum {requires com.squeed.nforum;requires java.logging;

}

All modules depends on java.base

Page 17: Jigsaw - Javaforum 2015Q4

Encapsulation

module com.squeed.javaforum {exports com.squeed.javaforum.agenda;exports com.squeed.javaforum.party to somemodule;

}

Second export is a qualified export

Page 18: Jigsaw - Javaforum 2015Q4

Encapsulation

public

protected

<package>

private

Page 19: Jigsaw - Javaforum 2015Q4

Encapsulationpublic to everyone

public to specific modules

public within a module

public

protected

<package>

private

Page 20: Jigsaw - Javaforum 2015Q4

Reflection

setAccessible(true)

Is enforced by the compiler, VM and core reflection

Page 21: Jigsaw - Javaforum 2015Q4

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

Page 22: Jigsaw - Javaforum 2015Q4

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

Page 23: Jigsaw - Javaforum 2015Q4

Q & A (maybe)