Jigsaw - Javaforum 2015Q4

Post on 12-Apr-2017

237 views 0 download

Transcript of Jigsaw - Javaforum 2015Q4

JigsawA long winding road started almost 8

years ago...

About the speakers

Rikard Thulin Fredrik Jansson

History: It started with a warjar cvf jigsaw.war

SUN Oracle OSGi

Obvious solutionApply 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 SystemSpec 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: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

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

}

ModulesThe 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

Encapsulationpublic 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)