SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
1.
Java SE 9, Project Jigsaw
Elek Márton
@anzix
2015 March
DPC Consulting
2.
Java 9 roadmap
2015/09/08 Mark Reinhold: The state of the
module system (Java 9 b83)
2015/12/10 Feature Complete
2016/02/04 All Tests Run
2016/02/25 Rampdown Start
2016/04/21 Zero Bug Bounce
2016/06/16 Rampdown Phase 2
2016/07/21 Final Release Candidate
2016/09/22 General Availability
6.
Related JEPs/JSR
JEP 200: The Modular JDK
JEP 201: Modular Source Code
JEP 220: Modular Run-Time Images
JEP 162: Prepare for Modularization (Java8)
JSR 376: Java Platform Module System
Good source:
Mark Reinhold: The state of the module system
7.
Getting started
Create your first module:
● traditional JAR file with
● module-info.java
module hu.dpc.java9.logger {
}
8.
Compile the module
● Could be compiled with standard tools (maven) if
there are no dependencies
● Command line tools are also changed
javac
-d /tmp/modules/hu.dpc.java9.logger
-modulepath /tmp/modules
-sourcepath src/main/java …..java
9.
Using the logger
Create your first module:
● traditional JAR file with
● module-info.java
module hu.dpc.java9.logger {
exports hu.dpc.java9.logger;
}
10.
Using logger
public class App {
public static void main(String[] args)
LoggerFactory.getLogger().log("Hello world");
}
}
module hu.dpc.java9.app {
requires hu.dpc.java9.logger;
}
11.
Package level dependencies
Source: M Reinhold: The state of the
module system
12.
Why we need classloaders?
● Classloader is for creating new classes
● Reference to a class could be used even without
explicit export
LoggerImpl
App
LoggerFactory
Logger
exports
requires
13.
Compile and run
javac
-d /tmp/modules/hu.dpc.java9.logger
-modulepath /tmp/modules
-sourcepath src/main/java ....java
java
-mp /tmp/modules
-m hu.dpc.java9.app/hu.dpc.java9.App
15.
Packaging: jmod
● Accommodate native code, configuration files, and
other kinds of data
● "Whether this new format, provisionally named
“JMOD,” should be standardized is an open
question."
16.
JDK modules
● Most of the APIs
are modularized
● can’t be used
without proper
requires in
module-info
18.
Service Layer
logger-framework.jar
logger-mysql.jar
interface Logger{...}
class MysqlLogger{...}
class LoggerFactory{...
19.
Service Layer
logger-framework.jar
logger-syslog.jar
interface Logger{...}
class SyslogLogger{...}
class LoggerFactory{...
20.
Service Layer - Java 6-8
Service Provider Interface
● Which are the implementation of a specific
interface?
ServiceLoader<Logger> loggers =
ServiceLoader.load(Logger.class);
for (Logger logger: loggers) {
logger.log("hello world");
}
}
21.
Service Layer - Java 6-8
ServiceLoader<Logger> loggers =
ServiceLoader.load(Logger.class);
for (Logger logger: loggers) {
logger.log("hello world");
}
}
Definition (in the jar file):
META-INF/services/hu.dpc.java9.logger.Logger
hu.dpc.java9.logger.internal.LoggerImpl
22.
Service Layer - Java 6-8
logger-framework.jar
logger-mysql.jar
interface Logger{...}
class MysqlLogger{...}
class LoggerFactory{...
23.
Service Layer - Java 9
Usage:
ServiceLoader<Logger> loggers =
ServiceLoader.load(Logger.class);
for (Logger logger: loggers) {
logger.log("hello world");
}
}
24.
Definition
In the hu.dpc.java9.logger module:
module hu.dpc.java9.logger {
exports hu.dpc.java9.logger;
provides hu.dpc.java9.logger.Logger
with hu.dpc.java9.logger.internal.LoggerImpl;
}
In the hu.dpc.java9.app module
module hu.dpc.java9.app {
requires hu.dpc.java9.logger;
use hu.dpc.java9.logger.Logger;
}
25.
Non requirements
● Modularize the Java Language Specification
● Modularize the Java Virtual Machine Specification
● Multiple versions
● Version selection
● Strict classloader requirements
See: http://openjdk.java.net/projects/jigsaw/spec/reqs/
26.
Java 9 vs OSGi
Java 9 / Jigsaw OSGi
metadata module-info.java (nincs meta adat) META-INF
classpath
separation
exports/requires Import-Package/Export-Package
classpath++ transitive imports, fragment bundle/dynamic import
classloader
hierarchy
ClassLoader: unspecified strict, per bundle
service layer static (get implementations) dynamic (get implemetations +
start/stop listeners)
services interface + implementation for the standard
services (logging, config...)
versioning no yes
27.
Summary/Future
● Summary
– classpath separation: private/public
– service locator (based on existing SPI)
– modularized JVM APIs
● Not scope
– versioning!
– strict class loader rules
● Shoud be upgraded:
– all the IDEs
– all the build tools (maven, gradle)
– all the JVM based languages (Scala, Clojure)
● SPI
– could be more widely adopted