SlideShare a Scribd company logo
OSGi and Java 9+ BJ Hargrave, IBM
Java 9 introduced the Java Platform Module System (JPMS)
• JPMS was primarily added to Java to enable modularization of the Java
platform
• Internals can be encapsulated to avoid dependencies - sun.misc.Unsafe
• Platform can be safely subset - jlink
• But JPMS can also be used by application code running on the platform
• But migration from plain JAR to module is a huge challenge
• It really depends on the bottom level dependencies going first
But JPMS really falls short for general use in applications
• The Java platform is a single code base, so all the modules are built together
and releases together
• Applications are almost never like this, they are composed of many modules
• From many sources including open source projects
• Released individually on their own schedules
• Potential for version conflicts in shared dependencies
Main Shortfalls
• Isolation - JPMS uses a single class loader per layer by default. So your non-exported
(private) packages can conflict with someone else’s non-exported (private) packages:
shadowing.
• Identity dependency - Modules depend upon the names of other module not things used
at runtime: classes in packages. So module names are API. As are transitive requirements
• Access restrictions - Reflection is not allowed unless you “open” your module. This is a
challenge for dependency injection and annotation scanning. You often don’t and
shouldn’t know the name of the module which needs to reflect upon you nor should you
put code, which needs reflection, in exported packages.
• Versioning - ??? Someone else’s problem. Like yours!
Java 9+ support in OSGi Core R7
Changes in Core R7 for Java 9+
• Multi-Release JARs (MRJAR)
• Runtime discovery of platform packages
• Bundle can import java.* packages
• Backwards compatible with pre-Java 9 and past releases of OSGi Core
Multi-Release JARs (MRJAR)
• A MRJAR file allows for a single JAR to support multiple major versions of the Java platform
• For example, a MRJAR file can depend on both the Java 8 and Java 9 major platform releases,
where some class files depend on APIs from Java 8 and other class file depend on APIs added
in Java 9
• The purpose is to support alternative implementations of select classes to deal with changes in the
visible APIs of the Java platform
• It is not meant as a means to supply new function or new API on different Java platform versions
• Only supported on Java 9 and above
• Multi-Release: true
MRJAR example
META-INF/MANIFEST.MF
com/example/foo/Bar.class
com/example/foo/bar.properties
META-INF/versions/9/com/example/foo/Bar.class
META-INF/versions/10/com/example/foo/bar.properties
META-INF/versions/11/com/example/foo/Bar.class
MRJAR Java 8 effective content
META-INF/MANIFEST.MF
com/example/foo/Bar.class
com/example/foo/bar.properties
META-INF/versions/9/com/example/foo/Bar.class
META-INF/versions/10/com/example/foo/bar.properties
META-INF/versions/11/com/example/foo/Bar.class
MRJAR Java 9 effective content
META-INF/MANIFEST.MF
com/example/foo/Bar.class
com/example/foo/bar.properties
META-INF/versions/9/com/example/foo/Bar.class
META-INF/versions/10/com/example/foo/bar.properties
META-INF/versions/11/com/example/foo/Bar.class
MRJAR Java 10 effective content
META-INF/MANIFEST.MF
com/example/foo/Bar.class
com/example/foo/bar.properties
META-INF/versions/9/com/example/foo/Bar.class
META-INF/versions/10/com/example/foo/bar.properties
META-INF/versions/11/com/example/foo/Bar.class
MRJAR Java 11 effective content
META-INF/MANIFEST.MF
com/example/foo/Bar.class
com/example/foo/bar.properties
META-INF/versions/9/com/example/foo/Bar.class
META-INF/versions/10/com/example/foo/bar.properties
META-INF/versions/11/com/example/foo/Bar.class
Multi-Release Bundles
• A bundle can be a multi-release bundle when it has Multi-Release: true in its manifest
• When a bundle is multi-release, the framework must look for the presence of a supplemental manifest
in a versioned folder of the bundle
• META-INF/versions/9/OSGI-INF/MANIFEST.MF
• The supplemental manifest, from the highest versioned folder, can contain Import-Package and
Require-Capability headers which replace the headers from the main manifest
• Since the alternate class implementations in the versioned folder can require different dependencies
• As a best practice, a supplemental manifest should not contain additional requirements on
capabilities which are not supplied by the Java platform for the Java version associated with the
supplemental manifest
Multi-Release Containers
• In additional to the bundle itself, a bundle’s class path can specify multiple
containers and each container can also be multi-release
• Bundle-ClassPath: ., libs/foo.jar
• A container must have Multi-Release: true in its manifest to be
recognized as a multi-release container
• When a container is a multi-release container, the framework must look in the
versioned folders when attempting to locate a class or resource in the
container
Runtime discovery of platform packages
• Now that the Java platform is modularized, the platform can be configured to
load only certain modules
• You can have a smaller, custom runtime that is tailored to the needs of a
specific application => jlink
• So the set of java.* packages provide by the running Java platform is no
longer constant for a specific version of the Java platform!
• So R7 frameworks must ask the platform for the current set of java.*
packages and use that to set the
org.osgi.framework.system.packages property
Importing java.* packages
• Bundle have used a requirement on the osgi.ee capability as a proxy for the set of java.*
packages they may require
• Given that the set of available java.* packages can vary, the osgi.ee requirement can
now only be used to express the JVM requirement
• e.g. Java 10 class file support needed
• Bundles are now permitted to list java.* packages in their Import-Package
• This can be used by the framework to resolve the bundle to ensure their java.* package
requirements can be met
• But class loading for java.* packages is still the same: parent delegation
Experiments
Credit
• Tom Watson is the mad genius behind these OSGi experiments with JPMS
• So all credit goes to Tom
• I am just reporting on them
“OSGi Sandwich” - https://github.com/tjwatson/osgi-jpms-layer
Java Module Layers and OSGi Bundles: First Try
Java Module Layers and OSGi Bundles: Second Try
Atomos - https://github.com/tjwatson/atomos
Tools
Tooling
• Bnd support
• MRJARs
• Import java.* packages when targeting Core R7
• Make jars that are bundles and modules?
• Automatic enrichment of module-info based upon annotations?
• Shading non-exported packages?
Thanks!
Evaluate the Sessions
-1 0 +1
Sign in and vote at eclipsecon.org

More Related Content

PDF
Jax london 2011
PDF
Architecture | Modular Enterprise Applications | Mark Nuttall
ODP
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
PDF
The evolution of OpenJDK: From Java's beginnings to 2014
PPT
Frc java5-8andeclipse
PDF
Disco API - OpenJDK distributions as a service
PPT
Managing Change
PPTX
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Jax london 2011
Architecture | Modular Enterprise Applications | Mark Nuttall
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
The evolution of OpenJDK: From Java's beginnings to 2014
Frc java5-8andeclipse
Disco API - OpenJDK distributions as a service
Managing Change
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose

What's hot (20)

PPTX
Introduction to OSGi
PDF
Understanding Java Dynamic Proxies
PDF
Tuscany : Applying OSGi After The Fact
PDF
Apache Maven In 10 Slides
PPTX
System Architecture using Maven Modularity
PDF
MyFaces CODI Conversations
PDF
itft-Java evolution
KEY
Wonderful World of Maven
PPTX
S/W Design and Modularity using Maven
PDF
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
PPTX
JavaPerformanceChapter_3
PDF
Polygot Java EE on the GraalVM
PDF
Dynamic Proxy by Java
PPTX
開放原始碼 Ch1.2 intro - oss - apahce foundry (ver 2.0)
PDF
JRuby in the enterprise
PDF
Delving Deeper Into OSGI Modularity
PPT
The Evolution of Java
PDF
AtoM feature development
PPTX
History of java'
PPTX
Java History
Introduction to OSGi
Understanding Java Dynamic Proxies
Tuscany : Applying OSGi After The Fact
Apache Maven In 10 Slides
System Architecture using Maven Modularity
MyFaces CODI Conversations
itft-Java evolution
Wonderful World of Maven
S/W Design and Modularity using Maven
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
JavaPerformanceChapter_3
Polygot Java EE on the GraalVM
Dynamic Proxy by Java
開放原始碼 Ch1.2 intro - oss - apahce foundry (ver 2.0)
JRuby in the enterprise
Delving Deeper Into OSGI Modularity
The Evolution of Java
AtoM feature development
History of java'
Java History
Ad

Similar to OSGi and Java 9+ (20)

PDF
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
PPTX
What’s expected in Java 9
PDF
Haj 4344-java se 9 and the application server-1
PDF
A Journey through the JDKs (Java 9 to Java 11)
PDF
JavaOne 2016: Life after Modularity
PDF
Modules all the way down: OSGi and the Java Platform Module System
PDF
Java SE 9 modules (JPMS) - an introduction
PDF
OpenJDK Penrose Presentation (JavaOne 2012)
PDF
Java modularity: life after Java 9
PPTX
Introduction to OSGi - Part-1
PPTX
Preparing for java 9 modules upload
PPTX
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
KEY
Introduction to EclipseRT (JAX 2010)
PDF
Java SE 9 modules - an introduction (July 2018)
PDF
Java 7 Modularity: a View from the Gallery
PDF
OSGI Modularity
PDF
Democamp - Munich - Java9
PPTX
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
PPTX
Java and OpenJDK: disecting the ecosystem
PPTX
Modular Java
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
What’s expected in Java 9
Haj 4344-java se 9 and the application server-1
A Journey through the JDKs (Java 9 to Java 11)
JavaOne 2016: Life after Modularity
Modules all the way down: OSGi and the Java Platform Module System
Java SE 9 modules (JPMS) - an introduction
OpenJDK Penrose Presentation (JavaOne 2012)
Java modularity: life after Java 9
Introduction to OSGi - Part-1
Preparing for java 9 modules upload
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Introduction to EclipseRT (JAX 2010)
Java SE 9 modules - an introduction (July 2018)
Java 7 Modularity: a View from the Gallery
OSGI Modularity
Democamp - Munich - Java9
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java and OpenJDK: disecting the ecosystem
Modular Java
Ad

More from bjhargrave (7)

PDF
The new OSGi LogService 1.4 and integrating with SLF4J
PDF
Constructor injection and other new features for Declarative Services 1.4
PDF
Field injection, type safe configuration, and more new goodies in Declarative...
PDF
Services-First Migration to OSGi
PDF
Why OSGi?
PDF
OSGi Puzzlers
KEY
OSGi 4.3 Technical Update: What's New?
The new OSGi LogService 1.4 and integrating with SLF4J
Constructor injection and other new features for Declarative Services 1.4
Field injection, type safe configuration, and more new goodies in Declarative...
Services-First Migration to OSGi
Why OSGi?
OSGi Puzzlers
OSGi 4.3 Technical Update: What's New?

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
AI in Product Development-omnex systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administraation Chapter 3
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PPTX
history of c programming in notes for students .pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms I-SECS-1021-03
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo POS Development Services by CandidRoot Solutions
AI in Product Development-omnex systems
Design an Analysis of Algorithms II-SECS-1021-03
Reimagine Home Health with the Power of Agentic AI​
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PTS Company Brochure 2025 (1).pdf.......
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administraation Chapter 3
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
history of c programming in notes for students .pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Digital Strategies for Manufacturing Companies
VVF-Customer-Presentation2025-Ver1.9.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development

OSGi and Java 9+

  • 1. OSGi and Java 9+ BJ Hargrave, IBM
  • 2. Java 9 introduced the Java Platform Module System (JPMS) • JPMS was primarily added to Java to enable modularization of the Java platform • Internals can be encapsulated to avoid dependencies - sun.misc.Unsafe • Platform can be safely subset - jlink • But JPMS can also be used by application code running on the platform • But migration from plain JAR to module is a huge challenge • It really depends on the bottom level dependencies going first
  • 3. But JPMS really falls short for general use in applications • The Java platform is a single code base, so all the modules are built together and releases together • Applications are almost never like this, they are composed of many modules • From many sources including open source projects • Released individually on their own schedules • Potential for version conflicts in shared dependencies
  • 4. Main Shortfalls • Isolation - JPMS uses a single class loader per layer by default. So your non-exported (private) packages can conflict with someone else’s non-exported (private) packages: shadowing. • Identity dependency - Modules depend upon the names of other module not things used at runtime: classes in packages. So module names are API. As are transitive requirements • Access restrictions - Reflection is not allowed unless you “open” your module. This is a challenge for dependency injection and annotation scanning. You often don’t and shouldn’t know the name of the module which needs to reflect upon you nor should you put code, which needs reflection, in exported packages. • Versioning - ??? Someone else’s problem. Like yours!
  • 5. Java 9+ support in OSGi Core R7
  • 6. Changes in Core R7 for Java 9+ • Multi-Release JARs (MRJAR) • Runtime discovery of platform packages • Bundle can import java.* packages • Backwards compatible with pre-Java 9 and past releases of OSGi Core
  • 7. Multi-Release JARs (MRJAR) • A MRJAR file allows for a single JAR to support multiple major versions of the Java platform • For example, a MRJAR file can depend on both the Java 8 and Java 9 major platform releases, where some class files depend on APIs from Java 8 and other class file depend on APIs added in Java 9 • The purpose is to support alternative implementations of select classes to deal with changes in the visible APIs of the Java platform • It is not meant as a means to supply new function or new API on different Java platform versions • Only supported on Java 9 and above • Multi-Release: true
  • 9. MRJAR Java 8 effective content META-INF/MANIFEST.MF com/example/foo/Bar.class com/example/foo/bar.properties META-INF/versions/9/com/example/foo/Bar.class META-INF/versions/10/com/example/foo/bar.properties META-INF/versions/11/com/example/foo/Bar.class
  • 10. MRJAR Java 9 effective content META-INF/MANIFEST.MF com/example/foo/Bar.class com/example/foo/bar.properties META-INF/versions/9/com/example/foo/Bar.class META-INF/versions/10/com/example/foo/bar.properties META-INF/versions/11/com/example/foo/Bar.class
  • 11. MRJAR Java 10 effective content META-INF/MANIFEST.MF com/example/foo/Bar.class com/example/foo/bar.properties META-INF/versions/9/com/example/foo/Bar.class META-INF/versions/10/com/example/foo/bar.properties META-INF/versions/11/com/example/foo/Bar.class
  • 12. MRJAR Java 11 effective content META-INF/MANIFEST.MF com/example/foo/Bar.class com/example/foo/bar.properties META-INF/versions/9/com/example/foo/Bar.class META-INF/versions/10/com/example/foo/bar.properties META-INF/versions/11/com/example/foo/Bar.class
  • 13. Multi-Release Bundles • A bundle can be a multi-release bundle when it has Multi-Release: true in its manifest • When a bundle is multi-release, the framework must look for the presence of a supplemental manifest in a versioned folder of the bundle • META-INF/versions/9/OSGI-INF/MANIFEST.MF • The supplemental manifest, from the highest versioned folder, can contain Import-Package and Require-Capability headers which replace the headers from the main manifest • Since the alternate class implementations in the versioned folder can require different dependencies • As a best practice, a supplemental manifest should not contain additional requirements on capabilities which are not supplied by the Java platform for the Java version associated with the supplemental manifest
  • 14. Multi-Release Containers • In additional to the bundle itself, a bundle’s class path can specify multiple containers and each container can also be multi-release • Bundle-ClassPath: ., libs/foo.jar • A container must have Multi-Release: true in its manifest to be recognized as a multi-release container • When a container is a multi-release container, the framework must look in the versioned folders when attempting to locate a class or resource in the container
  • 15. Runtime discovery of platform packages • Now that the Java platform is modularized, the platform can be configured to load only certain modules • You can have a smaller, custom runtime that is tailored to the needs of a specific application => jlink • So the set of java.* packages provide by the running Java platform is no longer constant for a specific version of the Java platform! • So R7 frameworks must ask the platform for the current set of java.* packages and use that to set the org.osgi.framework.system.packages property
  • 16. Importing java.* packages • Bundle have used a requirement on the osgi.ee capability as a proxy for the set of java.* packages they may require • Given that the set of available java.* packages can vary, the osgi.ee requirement can now only be used to express the JVM requirement • e.g. Java 10 class file support needed • Bundles are now permitted to list java.* packages in their Import-Package • This can be used by the framework to resolve the bundle to ensure their java.* package requirements can be met • But class loading for java.* packages is still the same: parent delegation
  • 18. Credit • Tom Watson is the mad genius behind these OSGi experiments with JPMS • So all credit goes to Tom • I am just reporting on them
  • 19. “OSGi Sandwich” - https://github.com/tjwatson/osgi-jpms-layer
  • 20. Java Module Layers and OSGi Bundles: First Try
  • 21. Java Module Layers and OSGi Bundles: Second Try
  • 23. Tools
  • 24. Tooling • Bnd support • MRJARs • Import java.* packages when targeting Core R7 • Make jars that are bundles and modules? • Automatic enrichment of module-info based upon annotations? • Shading non-exported packages?
  • 26. Evaluate the Sessions -1 0 +1 Sign in and vote at eclipsecon.org