16
Java9 Modules Tom Schindl <[email protected]> Twitter: @tomsontom Blog: http://tomsondev.bestsolution.at Website: http://www.bestsolution.at

Democamp - Munich - Java9

Embed Size (px)

Citation preview

Page 1: Democamp - Munich - Java9

Java9 Modules

Tom Schindl <[email protected]>

Twitter: @tomsontomBlog: http://tomsondev.bestsolution.atWebsite: http://www.bestsolution.at

Page 2: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

About Tom‣ CTO BestSolution.at Systemhaus GmbH

‣ Eclipse Committer

‣ e4

‣ Platform

‣ EMF

‣ Project lead

‣ e(fx)clipse

‣ Twitter: @tomsontom

‣ Blog: tomsondev.bestsolution.at

‣ Corporate: http://bestsolution.at

Page 3: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Targets of Java9 Modulesystem‣ Split up rt.jar in smaller junks

‣ Avoids further introduction of cross-references

‣ Allows smaller Java-Runtimes (eg for IoT-Devices, …)

‣ Restrict Access to internal APIs (eg com.sun.misc.Unsafe)

‣ Allow developers to adopt it for their code as well

Page 4: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ The Implementation

‣ OSGi Module System is built upon classloaders

‣ Java9 Module System is implemented at the VM Level

Page 5: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ The Implementation

‣ OSGi Module System is built upon classloaders

‣ Java9 Module System is implemented at the VM Level

OSGi

foo-1.0.0 (BundleLoaderClassLoader@f1)

bar-1.0.0 (BundleLoaderClassLoader@b1)

Page 6: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ The Implementation

‣ OSGi Module System is built upon classloaders

‣ Java9 Module System is implemented at the VM Level

OSGi

foo-1.0.0 (BundleLoaderClassLoader@f1)

bar-1.0.0 (BundleLoaderClassLoader@b1)

Java9

foo-1.0.0 (AppClassloader@A1)

bar-1.0.0 (AppClassloader@A1)

Page 7: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Dependency definition

‣ OSGi uses custom MANIFEST.MF entries Require-Bundle and Import-Package

‣ Java9 uses module-info.java and directive requires

Page 8: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Dependency definition

‣ OSGi uses custom MANIFEST.MF entries Require-Bundle and Import-Package

‣ Java9 uses module-info.java and directive requires

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: bar Require-Bundle: foo

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: bar Import-Package: foo

OSGi

Page 9: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Dependency definition

‣ OSGi uses custom MANIFEST.MF entries Require-Bundle and Import-Package

‣ Java9 uses module-info.java and directive requires

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: bar Require-Bundle: foo

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: bar Import-Package: foo

OSGimodule bar { requires foo; }

Java9

Page 10: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Access Restrictions

‣ OSGi uses custom MANIFEST.MF entry Export-Package

‣ Java9 use module-info.java and directive exports

Page 11: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Access Restrictions

‣ OSGi uses custom MANIFEST.MF entry Export-Package

‣ Java9 use module-info.java and directive exports

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: foo Export-Package: foo

OSGi

Page 12: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Access Restrictions

‣ OSGi uses custom MANIFEST.MF entry Export-Package

‣ Java9 use module-info.java and directive exports

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: foo Export-Package: foo

OSGimodule foo { exports foo; }

Java9

Page 13: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Services

‣ OSGi has eg Declarative Service Components and the BundleContext to lookup

Page 14: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Services

‣ OSGi has eg Declarative Service Components and the BundleContext to lookup

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: bar Require-Bundle: foo Service-Component: OSGI-INF/mycomponent.xml

<?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> <implementation class="bar.BarService"/> <service> <provide interface="foo.Service"/> </service> </scr:component>

Provider

Page 15: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Services

‣ OSGi has eg Declarative Service Components and the BundleContext to lookup

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: bar Require-Bundle: foo Service-Component: OSGI-INF/mycomponent.xml

<?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> <implementation class="bar.BarService"/> <service> <provide interface="foo.Service"/> </service> </scr:component>

ProviderBundleContext ctx = getContext(cl); ServiceReference<Service> ref = ctx.getServiceReference(Service.class); Service s = ctx.getService(ref);

Consumer

Page 16: Democamp - Munich - Java9

(c) BestSolution.at - Licensed under Creative Commons Attribution-NonCommerical-ShareAlike 3.0

Java9 Modules vs OSGi‣ Service

‣ Java9 uses module-info.java and ServiceLoader for the lookup

module bar { requires foo; provides foo.Service with bar.BarService; }

Providermodule foo { requires foo; uses foo.Service; }

Consumer

ServiceLoader<GreetService> l = ServiceLoader.load(Service.class); Service s = l.iterator().next();