OSGi provides a module system for Java applications by treating JAR files as bundles with additional metadata specifying things like name, version, dependencies, and exports/imports. This allows for greater modularity by resolving dependencies and supporting side-by-side versions. Components in OSGi are bundles that can be dynamically installed, updated, and uninstalled. Annotations and services allow bundles to be configured and discover other bundles at runtime.
6. Dependencies
JARs do have dependencies
They are implicit.
A dependency is an assumption.
“I assume module X (version Y) is on the
classpath. If not I will crash and burn.”
8. Just a JAR + Metadata
Meaningful name
Version
Vendor
org.foo.mylib
Manifest-Version: 1.0
Exports
Bundle-SymbolicName: com.mylib
Bundle-Name: My Library Bundle
Bundle-Vendor: Neil Bartlett
Bundle-Version: 1.0.0
Import-Package: javax.swing, org.w3c.dom
Export-Package: com.mylib1.ui;version=“1.0.0”,
com.mylib1.util;version=“1.0.0”
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Dependencies
22. Side-by-Side Versions
com.foo.bar com.foo.bar
B X
1.4.5 [1.4.0,1.5.0)
com.foo.bar com.foo.bar
B’ Y
1.3.12 [1.2.0,1.4.0)
23. Side-by-Side Versions
com.foo.bar com.foo.bar
B X
1.4.5 [1.4.0,1.5.0)
com.foo.bar com.foo.bar
B’ Y
1.3.12 [1.2.0,1.4.0)
24. How it Works
Bundle-SymbolicName: com.mylib1
Bundle-Version: 1.2.0
Export-Package:
com.mylib1.ui;version=“1.2.0”,
com.mylib1.util;version=“1.2.0”
Bundle-SymbolicName: com.app1
Bundle-Version: 2.2.3.alpha
Import-Package:
com.mylib1.ui;version=“[1.2.0,1.3.0)”
com.mylib1.util;version=“[1.2.0,1.3.0)”
25. Private Internals
Exports must be stated explicitly
Packages not listed in “Export-Package” are not
available to other bundles
26. Versions
Standard numbering scheme with well-defined
ordering.
major.minor.micro.qualifier
First three numeric, last alphanumeric
Eg 1.0.0.beta2
Unspecified ! 0.0.0
27. Version Ranges
Open, closed or implicit
[1.0.0, 2.0.0] ! 1.0.0 ! version ! 2.0.0
[1.0.0, 2.0.0) ! 1.0.0 ! version < 2.0.0
Informally “1.*”
1 ! [1.0.0, ")
Unspecified ! [0.0.0, ")
32. OSGi is the King of
Infrastructure
All Major JEE Application Servers use OSGi
Most ESBs use OSGi
2 of 3 Open Source IDEs use OSGi
Even Build Tools (Maven and Hudson) Moving to
OSGi
34. OSGi for Applications
Until Recently, Application Servers used OSGi “on
the inside”
Now SpringSource dm Server, Paremus Infiniflow,
WAS 7, GlassFish v3 and WebLogic DM all expose
OSGi
Application Developers can Finally Deploy OSGi
bundles to their OSGi servers!
35. Why is OSGi Attractive
for Application
Development?