SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
Project	Jigsaw	– Modularity	
at	language	level
Kamil Korzekwa
@kamkorz | blog.kamkor.me April	14,	2016
Project	Jigsaw	
• Adds	modularity	to	the	Java	
platform
• Hopefully coming	to	JDK	9	in	
March	2017
• Will	cause	compatibility	issues	
for	applications	that	use	JDK	
internal	APIs	(JEP	260)
How	is	it	different	from	tools	like	Maven?
Jigsaw	is	language	level	mechanism!
What’s	a	jigsaw	module?
• A grouping	of	code	
• For	example	Java	packages
• Can	contain	other	data	such	as
• resources
• configuration	files
• native	code	(for	example	when	using	JNI)
• Defined	in	the	module-info.java file
• File	is	placed	in	the	root	of	the	module	folder
• Can	be	packaged	as	jar
module-info.java file
• Module	has	a	symbolic	name	(that	only	looks	like	a	package)
• Module	exports	packages	(public	API)	to	other	modules
• Module	requires	dependencies	to	other	modules
module me.kamkor.foo {
exports me.kamkor.foo.api;
exports me.kamkor.foo;
requires java.sql;
}
Current naming
convention
Same	as	module	
name,	confusing	
enough?
public	!=	accessible	(fundamental	change	to	Java)
• public
JDK9
• public	to	everyone
module me.kamkor.foo {
exports me.kamkor.foo.api;
}
• public,	but	only	to	specific	modules
module me.kamkor.foo {
exports me.kamkor.foo.api to
me.kamkor.bar,
me.kamkor.magic;
}
• public	only	within	a	module
PRE-JDK9
Implied	readability
module me.kamkor.foo {
requires java.sql;
}
• Code	in	the	me.kamkor.foo module:
final Driver driver = DriverManager.getDriver(url);
final Logger logger = driver.getParentLogger();
logger.info(“Connection acquired”);
Logger is exported in
the java.logging module
Driver is exported in
the java.sql module
Implied	readability	
// assumed configuration (fake)
module java.sql {
requires java.logging;
..
}
Implied	readability
module java.sql {
requires public java.logging;
}
Implied	readability
• If	you	use	types	from	required	module	in	your	exported	types,	then	
consider	exposing	this	module	to	your	users	using	requires	public
• If	you	use	types	from	required	module	only	in	your	internal	code,	
then	do	not	expose	this	module	to	your	users
“Fun”	with	classpath
bin/greeter/GreetingProvider.class
bin/starwarsgreeter/GreetingProvider.class
bin/app/GreeterApp.class
Using default package
for the sake of simplicity
“Fun”	with	classpath
$ java -classpath bin/greeter:bin/app GreeterApp
Hello World
$ java -classpath bin/starwarsgreeter:bin/app GreeterApp
May the force be with you!
$ java -classpath bin/greeter:bin/starwarsgreeter:bin/app GreeterApp
Hello World
Classpath hell	– shadowing		
• Default	classloader loads	the	first	matching	class	it	finds
"The	order	in	which	you	specify	multiple	class	path	entries	is	important.	
The	Java	interpreter	will	look	for	classes	in	the	directories	in	the	order	
they	appear	in	the	class	path	variable.”	
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/class
path.html
Classpath hell	– real	world	examples	of	
shadowing
• Different	libraries	on	the	classpath contain	class	with	the	
same	fully	qualified	name
• Two	different	versions	of	the	same	library	are	on	the	
classpath
• Library	is	renamed	and	accidentally	added	to	the	classpath
twice
Modulepath to	the	rescue!
Classpath vs	modulepath
• Flat	structure
• Allows	to	locate	individual	types
• Default	classloader loads	the	
first	matching	class	it	finds	on	
the	classpath
Modulepath
• Graph	structure
• Allows	to	locate	modules	rather	
than	individual	types
• Java	is	aware	about	relationships	
between	the	modules
• Can	discover	potential	problems	
sooner
Classpath
Shadowing	fixed	with	Jigsaw	modulepath
• Compiling	Java	application	with	two	modules	on	the	modulepath that	
export	the	same	package
src/me.kamkor.foo/module-info.java:1: error:
module me.kamkor.foo reads package me.kamkor.beta from both
me.kamkor.bar1 and me.kamkor.bar2
Compile error
Shadowing	fixed	with	Jigsaw	modulepath
• Running	Java	application	with	two	modules	on	the	modulepath that	
have	the	same	name
Error occurred during initialization of VM
java.lang.module.ResolutionException: Two versions of module
me.kamkor.bar found in mods
Error when trying to
run application
Module	version	selection
• Version	selection	is	left	for	the	dependency-resolution	
mechanisms	such	as	Maven,	Gradle,	sbt	etc.
http://openjdk.java.net/projects/jigsaw/goals-reqs/03#version-
selection
Multiple	module	versions
• Jigsaw	allows	only	one	
version	of	module	in	single	
configuration	
• Dependency	resolution	
mechanism	must	pick	one
• Modulepath version	hell	just	
like	classpath version	hell
http://openjdk.java.net/projects
/jigsaw/goals-reqs/03#version-
selection
Circular	dependencies
module me.kamkor.foo {
requires me.kamkor.bar;
}
module me.kamkor.bar {
requires me.kamkor.foo;
}
./src/me.kamkor.foo/module-info.java:2: error: cyclic
dependence involving me.kamkor.bar requires me.kamkor.bar;
Compile error
Better	JDK	with	the	use	of	Project	Jigsaw
JDK	is	BIG!
• 4000+	classes	in	rt.jar
(classes.jar on	Macs)
• java.util.List etc.
• All	loaded	on	start	by	the	
bootstrap	classloader
• Does	your	application	really	
need	all	of	them?
(source:	Liguori,	R.,	Liguori,	 P.:	Java	8	Pocket	Guide)
JDK	will	be	split	into	modules
http://openjdk.java.net/jeps/200
JDK	Structure	(simplified)
bin
java
javac
jre
bin java
lib rt.jar
lib tools.jar
JDK9
bin
java
javac
conf
jmods
lib
Pre-JDK9
jre directory
rt.jar
tools.jar
jlink – The	Java	Linker
“Create	a	tool	that	can	assemble	and	optimize	a	set	of	modules	and	
their	dependencies	into	a	custom	run-time	image	as	defined	in	JEP	
220.”
http://openjdk.java.net/jeps/282
jlink – The	Java	Linker
$ jlink --modulepath $JAVA_HOME/jmods:mlib 
--addmods me.kamkor.greeter --output executable 
--strip-debug --compress=2
$ tree –L 1 executable
executable
bin
conf
lib
jlink – The	Java	Linker
$ du -h -d 0 executable
20M executable
$ executable/bin/me.kamkor.greeter
Greetings World!
jlink – The	Java	Linker
$ executable/bin/java -listmods
java.base@9-ea
me.kamkor.greeter
me.kamkor.foo@1.0
Version is just
for information
purposes
Compatibility	&	Migration
• Applications	can	still	use	classpath
• JDK	will	be	split	into	modules.	Applications	may	be	affected	if	they	
used	internal	APIs	of	the	JDK	(JEP	260)
• Applications	can	be	split	into	Jigsaw	modules	in	small	steps.	Migration	
guide:
• http://openjdk.java.net/projects/jigsaw/spec/sotms/#compatibility--
migration
Project	Jigsaw	summary
• Improved	maintainability	of	JDK	and	user	applications
• Stronger	encapsulation	(modules	export	public	APIs)
• Reliable	configuration	with	modulepath that	replaces	error	prone	classpath
mechanism
• Improved	security	of	applications
• Less	APIs	make	the	attack	surface	smaller
• Improved	Java	platform	scalability	and	flexibility
• Configurable	modular	JDK
• Run-time	images	(jlink – the	Java	Linker	tool)
• Improved	performance	of	applications
• Start	up	performance	improvements	(less	classes	to	load	by	the	bootstrap	
classloader)
Impact	of	Project	Jigsaw
• I	hope	that	it	will	speed	up	the	development	of	the	JDK
• Will	it	be	widely	adopted	by	the	developers?
• Spring	5	will	support	Jigsaw	out	of	the	box	
• Spring	will	do	everything	it	can	to	allow	you	to	use	Jigsaw
• Spring	jars	(spring-mvc,	spring-jdbc etc.)	will	be	configured	as	Jigsaw	modules
• http://www.infoq.com/presentations/spring-framework-5
Useful	resources
• https://github.com/AdoptOpenJDK/jdk9-jigsaw
• http://openjdk.java.net/projects/jigsaw/spec/sotms/
• http://openjdk.java.net/projects/jigsaw/
Thank	you,	questions?

Weitere ähnliche Inhalte

Ähnlich wie Project Jigsaw - modularity at language level

Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
njbartlett
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Martin Toshev
 

Ähnlich wie Project Jigsaw - modularity at language level (20)

Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Java 9 / Jigsaw - LJC / VJUG session (hackday session)Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil BartlettJava Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
Java Platform Module System
Java Platform Module SystemJava Platform Module System
Java Platform Module System
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)
 
Modular Java
Modular JavaModular Java
Modular Java
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG session
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Eclipse JDT Embraces Java 9 – An Insider’s View
Eclipse JDT Embraces Java 9 – An Insider’s ViewEclipse JDT Embraces Java 9 – An Insider’s View
Eclipse JDT Embraces Java 9 – An Insider’s View
 
Modularization in java 8
Modularization in java 8Modularization in java 8
Modularization in java 8
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
Spring to Image
Spring to ImageSpring to Image
Spring to Image
 
Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module System
 
Saveface - Save your Facebook content as RDF data
Saveface - Save your Facebook content as RDF dataSaveface - Save your Facebook content as RDF data
Saveface - Save your Facebook content as RDF data
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
 
Vba Macros Interoperability
Vba Macros InteroperabilityVba Macros Interoperability
Vba Macros Interoperability
 
01 spring-intro
01 spring-intro01 spring-intro
01 spring-intro
 

Kürzlich hochgeladen

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Kürzlich hochgeladen (20)

The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Project Jigsaw - modularity at language level