Project Jigsaw_ Florian Trobach whoami codecentric Karlsruhe - - PowerPoint PPT Presentation

project jigsaw
SMART_READER_LITE
LIVE PREVIEW

Project Jigsaw_ Florian Trobach whoami codecentric Karlsruhe - - PowerPoint PPT Presentation

Project Jigsaw_ Florian Trobach whoami codecentric Karlsruhe Plain Old Java Dev Currently trying to tame the SMACK stack 2 Services 3 Modules can provide services java.util.ServiceLoader 4 Modules can provide services


slide-1
SLIDE 1

Project Jigsaw_

Florian Troßbach

slide-2
SLIDE 2

whoami

  • codecentric Karlsruhe
  • Plain Old Java Dev
  • Currently trying to tame the

SMACK stack

2

slide-3
SLIDE 3

Services

3

slide-4
SLIDE 4

Modules can provide services

  • java.util.ServiceLoader

4

slide-5
SLIDE 5

Modules can provide services

  • Modules provide service implementations
  • Other modules can use services
  • ServiceLoader finds all implementations on the

module path

  • No dependency on the providing modules needed

=> decoupling!

5

slide-6
SLIDE 6

Example

6 module org.codefx.demo.advent { // list the required modules requires org.codefx.demo.advent.calendar; // list the used services uses org.codefx.demo.advent.surprise.SurpriseFactory; } module org.codefx.demo.advent.factory.quote { requires public org.codefx.demo.advent.surprise; // specify which class provides which service provides org.codefx.demo.advent.surprise.SurpriseFactory with org.codefx.demo.advent.factory.quote.QuoteFactory; }

slide-7
SLIDE 7

Example

7 Diagram by Nicolai Parlog, http://blog.codefx.org/java/dev/jigsaw-hands-on-guide/

slide-8
SLIDE 8

Working with non-modular code

8

slide-9
SLIDE 9

Non-modular code

  • Using libraries
  • Spring, Guava, …
  • your internal library
  • Using modular code from

non-modular code

9

A u t

  • m

a t i c m

  • d

u l e s U n n a m e d m

  • d

u l e

slide-10
SLIDE 10

Automatic modules

What is the name of an automatic module?

  • The name of the jar
  • guava.jar => “guava”
  • guava-19.0.jar

10

slide-11
SLIDE 11

Automatic modules

What does an automatic module export?

  • All its packages
  • => All public types

11

slide-12
SLIDE 12

Automatic modules

What does an automatic module require?

  • All exports of all modules on the module

path

  • All public types in the unnamed module

12

slide-13
SLIDE 13

The unnamed module

What is the name of the unnamed module?

  • Any guesses?

13

slide-14
SLIDE 14

The unnamed module

What does the unnamed module export?

  • All its packages
  • requires unnamed;

14

slide-15
SLIDE 15

The unnamed module

What does an the unnamed module require?

  • All exports of all modules on the module

path

15

slide-16
SLIDE 16

Named Modules

Overview

16 [..].advent java.base [..].advent.surprise guava Unnamed module commons- io-2.4.0.jar commons-lang.jar

slide-17
SLIDE 17

Example

17

slide-18
SLIDE 18

Breaking Jigsaw - Live

18

slide-19
SLIDE 19

jlink

19

slide-20
SLIDE 20

Build your own JRE!

  • Create your own Java runtime
  • Pick which modules to include
  • Can lead to really small distributions (< 15 MB)

20

slide-21
SLIDE 21

Example

21

slide-22
SLIDE 22

Resources

  • https:/

/github.com/ftrossbach/demo-jigsaw-advent-calendar

  • Mark Reinhold, “The State of the Module System”
  • http:/

/openjdk.java.net/projects/jigsaw/spec/sotms/

  • Nicolai Parlog’s posts on Jigsaw
  • http:/

/blog.codefx.org/tag/project-jigsaw/

  • My blog posts on Jigsaw
  • https:/

/blog.codecentric.de/en/2015/11/first-steps-with-java9- jigsaw-part-1/

  • https:/

/blog.codecentric.de/en/2015/12/first-steps-with-java9- jigsaw-part-2/

22