SlideShare a Scribd company logo
1 of 29
Download to read offline
June 10-11, 2008 Berlin, Germany
Everything can be a bundle –
Making OSGi bundles of Java legacy code
Erik Wistrand
wistrand@makewave.com
Gunnar Ekolin
ekolin@makewave.com
2
•! Lots of Java code has been written taking stuff for
granted
•! Just one classloader
•! System.exit() is OK to call
•! A file system is present
•! A static main() method is used for start-up
•! ...
...this leads to classloading problems, premature
exit of the entire framework and various internal
bugs
What's the problem?
3
The Knopflerfish OSGi framework contains code
that can
•! Start jar files with only a static main method
•! Automatically import/export packages
•! Patch code that uses “bad” methods regarding
classloading etc.
What can be done?
4
Installing a non-bundle JAR-file
•! The Auto-Manifest feature of Knopflerfish makes
it possible to take any jar file and install it as if it
where bundle
•! All contained packages will be exported
•! Dynamic-Import: * used to get access to shared
packages.
5
Auto-Manifest - Configuration
The file automanifest.props
1.match.filter=(location=*hello_world-app*)!
1.export.filter=(pkg=*)!
1.export.file.filter=(file=*.class)!
1.header.DynamicImport-Package=*
1.header.Import-Package=[remove]
1.header.Export-Package=[autoexport]
6
Auto-Manifest - Launch
java
-Dorg.knopflerfish.framework.automanifest=true
-Dorg.knopflerfish.framework.automanifest.config=
file:automanifest.props
-Dorg.knopflerfish.framework.debug.automanifest=
true
-jar framework.jar
7
Demo: Hello World
•! Install the Hello World application
hello_world-app-1.0.0.jar
•! The demos are available for download from
http://www.knopflerfish.org/demos/knopflerfish-osgi-berlin-2008.zip
8
Main-Class as Activator - Launch
java
-Dorg.knopflerfish.framework.automanifest=true
-Dorg.knopflerfish.framework.automanifest.config=
file:automanifest.props
-Dorg.knopflerfish.framework.debug.automanifest=
true
-Dorg.knopflerfish.framework.main.class.activation=
file:jars/hello_world-app/hello_world-app-1.0.0.jar
-jar framework.jar
9
System.exit()!
•! An application normally calls System.exit(0)
to terminate.
•! This will kill the entire OSGi framework.
•! Common workaround:
•! Modify the application source to be OSGi aware and
recompile.
•! Impractical.
•! License issues.
•! Source may not be available.
10
SinceallbundleclassesareloadedviatheOSGiframework,theframeworkcanmodify
th
e
byte-code on the fly to use the correct classloader:
1. Load original byte code.
2. Find occurrences of “wrong” method calls.
3. Replace with call to “right” method.
4. Use the modified class.
(5. Profit!)!
A new approach – automatic byte code
modification
11
BundleClassLoader
The Knopflerfish implementation
Bundle Patched BundleASM
patches.props
12
•! Uses the ASM byte-code manipulation library.
•! A configuration file can specify which bundles/
classes should be modified.
•! Bundles are automatically modified as they are
loaded.
Yes, this is a poor man's aspect oriented
framework.
btw, LDAP filters are the best thing since sliced
bread. Yes, they are!
The Knopflerfish implementation
13
Default set of patches
•! java.lang.ClassLoader.getSystemClassLoader()!
•! Returns the bundle classloader.
•! java.lang.System.exit(int)!
•! Calls BundleContext.stop(), disabled by default.
•! java.lang.Class.forName(String)!
•! First tries the default classloader, then the bundle's classloader.
•! java.lang.Class.forName(String,boolean,ClassLoader)!
•
F
irst tries the specified classloader, then the bundle's classloader.
14
Patching - Launch
java
-Dorg.knopflerfish.framework.patch=true
-Dkf.patch.systemExitWrapper=true
-cp framework.jar:asm-3.1.jar
org.knopflerfish.framework.Main
15
Demo: Hello World
•! Start the Hello World application and stop it by
closing the window.
•! Same thing again with default bundle patching
enabled.
•! The demos are available for download from
http://www.knopflerfish.org/demos/knopflerfish-osgi-berlin-2008.zip
16
Classloading problems
•! Old, non-OSGi-aware libraries can easily be
wrapped as an OSGi bundle.
•! Sounds easy, just create a manifest file and export/
import the necessary stuff,
...but they may still run into classloading problems.
ClassNotFoundException:
Cannot find com.acme.ICustomer
17
Why ClassNotFoundException
•! For the OSGi import/export mechanism to work,
the bundle must use the Bundle classloader.
•! However, many libraries uses the system
classloader or the thread's classloader
•! Works great in standalone apps
•! Does not work at all in typical OSGi settings
18
package mypackage;
class Foo {
System classloader
Bundle classloader
mypackage.Foo.class
mypackage.Bar.class
Class c = ...getContextClassLoader().loadClass(“mypackage.Bar”);
Class c = Foo.class.getClassloader().loadClass(“mypackage.Bar”);
OSGi framework
Fails!
ok!
19
•! Modifying the library source to be OSGi-aware
and recompile
•! Impractical
•! License issues
•! Wrapping each library call in code that sets the
thread's context class loader
•! Tricky to find all cases
•! Boilerplate code is a Bad Thing
•! Put all classes on the system class path!
•! Really just hurts
Common workarounds to fix classloading
20
Demo – run jEdit as a bundle
jEdit bundle
Knopflerfish OSGi + ASM
jEdit 4.2 std distribution
Std OSGi bundles
Wrapper methods
JVM
21
Let's patch all library calls to
Class.forName(String name,
boolean init,
ClassLoader cl)!
Example patch
22
public static
Class forName3Wrapper(String name,
boolean initialize,
ClassLoader cl,
long bid,
Object context)
throws ClassNotFoundException
{
// use bundle classloader instead
return ...
}
First, write the wrapper method
23
•!Find the string signature of the method to be patched
java/lang/Class.forName(Ljava/lang/
String;ZLjava/lang/ClassLoader;)Ljava/
lang/Class;
•!Find the string signature or the static wrapper
method that should replace the above call
org/knopflerfish/framework/
ClassPatcherWrappers.forName3Wrapper
Next, find signature strings
24
patch.1.from= java/lang/Class.
forName(Ljava/lang/String;ZLjava/lang/ClassLoader;)
Ljava/lang/Class;
p
at
ch.1.to= org/knopflerfish/framework/ClassPatcherWrappers.
forName3Wrapper
patch.1.static=true
patch.1.active=true
# Optional LDAP-filter with keys: classname, methodname, methoddesc,
# methodaccess, bid, location and all manifest headers.
patches.filter=(&(!(classname=org.knopflerfish.*))
(!(classname=org.osgi.*))(location=*))!
Create configuration file
25
Specify Configuration File
•! A global (default) patch configuration file can be
specified as the value of the (system) property:
org.knopflerfish.framework.patch.configurl
•! Each bundle can specify a bundle specific
patch configuration file via the manifest
header:
Bundle-ClassPatcher-Config:!/patches.props
26
java 
-Dorg.knopflerfish.framework.patch=true 
-Dorg.knopflerfish.framework.patch.configurl=
file:patches.props 
-cp framework.jar:asm-3.1.jar 
org.knopflerfish.framework.Main
...and launch
27
Upcoming changes
•! Today the patching engine is part of the
framework.
•! It will be moved out to a separate bundle using
an API similar to
java.lang.instrumentation.ClassFileTransformer
June 10-11, 2008 Berlin, Germany
Q&A
Gunnar Ekolin
ekolin@makewave.com
June 10-11, 2008 Berlin, Germany
Everything can be a bundle –
Making OSGi bundles of Java legacy code
Erik Wistrand
wistrand@makewave.com
Gunnar Ekolin
ekolin@makewave.com

More Related Content

What's hot

mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingHaim Yadid
 
Thread dump troubleshooting
Thread dump troubleshootingThread dump troubleshooting
Thread dump troubleshootingJerry Chan
 
Asynchronous I/O in Python 3
Asynchronous I/O in Python 3Asynchronous I/O in Python 3
Asynchronous I/O in Python 3Feihong Hsu
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMatt Butcher
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Dist::Zilla - A very brief introduction
Dist::Zilla - A very brief introductionDist::Zilla - A very brief introduction
Dist::Zilla - A very brief introductionDean Hamstead
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
Ahead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java ApplicationsNikita Lipsky
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassCODE WHITE GmbH
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you pownedDinis Cruz
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Anton Arhipov
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Charles Nutter
 
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration DisastersBSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disastersinfodox
 
Power of linked list
Power of linked listPower of linked list
Power of linked listPeter Hlavaty
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 MinutesCharles Nutter
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Michael Barker
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projectsjazzman1980
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Tim Bunce
 

What's hot (20)

mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profiling
 
Thread dump troubleshooting
Thread dump troubleshootingThread dump troubleshooting
Thread dump troubleshooting
 
Asynchronous I/O in Python 3
Asynchronous I/O in Python 3Asynchronous I/O in Python 3
Asynchronous I/O in Python 3
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Dist::Zilla - A very brief introduction
Dist::Zilla - A very brief introductionDist::Zilla - A very brief introduction
Dist::Zilla - A very brief introduction
 
Attack on the Core
Attack on the CoreAttack on the Core
Attack on the Core
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Ahead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java Applications
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013
 
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration DisastersBSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
 
Power of linked list
Power of linked listPower of linked list
Power of linked list
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
 

Similar to Everything can be a bundle - making OSGi bundles of Java legacy code - Gunnar Ekolin, Makewave

Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...
Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...
Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...mfrancis
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...mfrancis
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming Saravanakumar R
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Jeffrey Groneberg
 
A toolbox for statical analysis and transformation of OSGi bundles
A toolbox for statical analysis and transformation of OSGi bundlesA toolbox for statical analysis and transformation of OSGi bundles
A toolbox for statical analysis and transformation of OSGi bundlesOSGi User Group France
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011njbartlett
 
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 BartlettJAX London
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
Third party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationshipThird party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationshipSascha Brinkmann
 
“Using C#/.NET – “Controversial Topics & Common Mistakes”
“Using C#/.NET – “Controversial Topics & Common Mistakes”“Using C#/.NET – “Controversial Topics & Common Mistakes”
“Using C#/.NET – “Controversial Topics & Common Mistakes”IT Weekend
 
A Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbert
A Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbertA Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbert
A Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbertJ On The Beach
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandCharles Nutter
 

Similar to Everything can be a bundle - making OSGi bundles of Java legacy code - Gunnar Ekolin, Makewave (20)

Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...
Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...
Everything can be a bundle — automatically repairing pre-OSGi code - Erik Wis...
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
Java Intro
Java IntroJava Intro
Java Intro
 
Java JVM
Java JVMJava JVM
Java JVM
 
Java Class Loader
Java Class LoaderJava Class Loader
Java Class Loader
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -
 
A toolbox for statical analysis and transformation of OSGi bundles
A toolbox for statical analysis and transformation of OSGi bundlesA toolbox for statical analysis and transformation of OSGi bundles
A toolbox for statical analysis and transformation of OSGi bundles
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
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
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Third party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationshipThird party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationship
 
“Using C#/.NET – “Controversial Topics & Common Mistakes”
“Using C#/.NET – “Controversial Topics & Common Mistakes”“Using C#/.NET – “Controversial Topics & Common Mistakes”
“Using C#/.NET – “Controversial Topics & Common Mistakes”
 
A Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbert
A Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbertA Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbert
A Post-Apocalyptic sun.misc.Unsafe World by Christoph engelbert
 
Javasession10
Javasession10Javasession10
Javasession10
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
Chapter 1 :
Chapter 1 : Chapter 1 :
Chapter 1 :
 

More from mfrancis

Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...mfrancis
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)mfrancis
 
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)mfrancis
 
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank LyaruuOSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruumfrancis
 
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...mfrancis
 
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...mfrancis
 
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...mfrancis
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)mfrancis
 
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...mfrancis
 
OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)mfrancis
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...mfrancis
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...mfrancis
 
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...mfrancis
 
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)mfrancis
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)mfrancis
 
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)mfrancis
 
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...mfrancis
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)mfrancis
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...mfrancis
 
How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)mfrancis
 

More from mfrancis (20)

Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
 
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
 
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank LyaruuOSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
 
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
 
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
 
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
 
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
 
OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
 
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
 
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
 
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
 
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
 
How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)
 

Recently uploaded

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Everything can be a bundle - making OSGi bundles of Java legacy code - Gunnar Ekolin, Makewave

  • 1. June 10-11, 2008 Berlin, Germany Everything can be a bundle – Making OSGi bundles of Java legacy code Erik Wistrand wistrand@makewave.com Gunnar Ekolin ekolin@makewave.com
  • 2. 2 •! Lots of Java code has been written taking stuff for granted •! Just one classloader •! System.exit() is OK to call •! A file system is present •! A static main() method is used for start-up •! ... ...this leads to classloading problems, premature exit of the entire framework and various internal bugs What's the problem?
  • 3. 3 The Knopflerfish OSGi framework contains code that can •! Start jar files with only a static main method •! Automatically import/export packages •! Patch code that uses “bad” methods regarding classloading etc. What can be done?
  • 4. 4 Installing a non-bundle JAR-file •! The Auto-Manifest feature of Knopflerfish makes it possible to take any jar file and install it as if it where bundle •! All contained packages will be exported •! Dynamic-Import: * used to get access to shared packages.
  • 5. 5 Auto-Manifest - Configuration The file automanifest.props 1.match.filter=(location=*hello_world-app*)! 1.export.filter=(pkg=*)! 1.export.file.filter=(file=*.class)! 1.header.DynamicImport-Package=* 1.header.Import-Package=[remove] 1.header.Export-Package=[autoexport]
  • 7. 7 Demo: Hello World •! Install the Hello World application hello_world-app-1.0.0.jar •! The demos are available for download from http://www.knopflerfish.org/demos/knopflerfish-osgi-berlin-2008.zip
  • 8. 8 Main-Class as Activator - Launch java -Dorg.knopflerfish.framework.automanifest=true -Dorg.knopflerfish.framework.automanifest.config= file:automanifest.props -Dorg.knopflerfish.framework.debug.automanifest= true -Dorg.knopflerfish.framework.main.class.activation= file:jars/hello_world-app/hello_world-app-1.0.0.jar -jar framework.jar
  • 9. 9 System.exit()! •! An application normally calls System.exit(0) to terminate. •! This will kill the entire OSGi framework. •! Common workaround: •! Modify the application source to be OSGi aware and recompile. •! Impractical. •! License issues. •! Source may not be available.
  • 10. 10 SinceallbundleclassesareloadedviatheOSGiframework,theframeworkcanmodify th e byte-code on the fly to use the correct classloader: 1. Load original byte code. 2. Find occurrences of “wrong” method calls. 3. Replace with call to “right” method. 4. Use the modified class. (5. Profit!)! A new approach – automatic byte code modification
  • 12. 12 •! Uses the ASM byte-code manipulation library. •! A configuration file can specify which bundles/ classes should be modified. •! Bundles are automatically modified as they are loaded. Yes, this is a poor man's aspect oriented framework. btw, LDAP filters are the best thing since sliced bread. Yes, they are! The Knopflerfish implementation
  • 13. 13 Default set of patches •! java.lang.ClassLoader.getSystemClassLoader()! •! Returns the bundle classloader. •! java.lang.System.exit(int)! •! Calls BundleContext.stop(), disabled by default. •! java.lang.Class.forName(String)! •! First tries the default classloader, then the bundle's classloader. •! java.lang.Class.forName(String,boolean,ClassLoader)! • F irst tries the specified classloader, then the bundle's classloader.
  • 15. 15 Demo: Hello World •! Start the Hello World application and stop it by closing the window. •! Same thing again with default bundle patching enabled. •! The demos are available for download from http://www.knopflerfish.org/demos/knopflerfish-osgi-berlin-2008.zip
  • 16. 16 Classloading problems •! Old, non-OSGi-aware libraries can easily be wrapped as an OSGi bundle. •! Sounds easy, just create a manifest file and export/ import the necessary stuff, ...but they may still run into classloading problems. ClassNotFoundException: Cannot find com.acme.ICustomer
  • 17. 17 Why ClassNotFoundException •! For the OSGi import/export mechanism to work, the bundle must use the Bundle classloader. •! However, many libraries uses the system classloader or the thread's classloader •! Works great in standalone apps •! Does not work at all in typical OSGi settings
  • 18. 18 package mypackage; class Foo { System classloader Bundle classloader mypackage.Foo.class mypackage.Bar.class Class c = ...getContextClassLoader().loadClass(“mypackage.Bar”); Class c = Foo.class.getClassloader().loadClass(“mypackage.Bar”); OSGi framework Fails! ok!
  • 19. 19 •! Modifying the library source to be OSGi-aware and recompile •! Impractical •! License issues •! Wrapping each library call in code that sets the thread's context class loader •! Tricky to find all cases •! Boilerplate code is a Bad Thing •! Put all classes on the system class path! •! Really just hurts Common workarounds to fix classloading
  • 20. 20 Demo – run jEdit as a bundle jEdit bundle Knopflerfish OSGi + ASM jEdit 4.2 std distribution Std OSGi bundles Wrapper methods JVM
  • 21. 21 Let's patch all library calls to Class.forName(String name, boolean init, ClassLoader cl)! Example patch
  • 22. 22 public static Class forName3Wrapper(String name, boolean initialize, ClassLoader cl, long bid, Object context) throws ClassNotFoundException { // use bundle classloader instead return ... } First, write the wrapper method
  • 23. 23 •!Find the string signature of the method to be patched java/lang/Class.forName(Ljava/lang/ String;ZLjava/lang/ClassLoader;)Ljava/ lang/Class; •!Find the string signature or the static wrapper method that should replace the above call org/knopflerfish/framework/ ClassPatcherWrappers.forName3Wrapper Next, find signature strings
  • 24. 24 patch.1.from= java/lang/Class. forName(Ljava/lang/String;ZLjava/lang/ClassLoader;) Ljava/lang/Class; p at ch.1.to= org/knopflerfish/framework/ClassPatcherWrappers. forName3Wrapper patch.1.static=true patch.1.active=true # Optional LDAP-filter with keys: classname, methodname, methoddesc, # methodaccess, bid, location and all manifest headers. patches.filter=(&(!(classname=org.knopflerfish.*)) (!(classname=org.osgi.*))(location=*))! Create configuration file
  • 25. 25 Specify Configuration File •! A global (default) patch configuration file can be specified as the value of the (system) property: org.knopflerfish.framework.patch.configurl •! Each bundle can specify a bundle specific patch configuration file via the manifest header: Bundle-ClassPatcher-Config:!/patches.props
  • 26. 26 java -Dorg.knopflerfish.framework.patch=true -Dorg.knopflerfish.framework.patch.configurl= file:patches.props -cp framework.jar:asm-3.1.jar org.knopflerfish.framework.Main ...and launch
  • 27. 27 Upcoming changes •! Today the patching engine is part of the framework. •! It will be moved out to a separate bundle using an API similar to java.lang.instrumentation.ClassFileTransformer
  • 28. June 10-11, 2008 Berlin, Germany Q&A Gunnar Ekolin ekolin@makewave.com
  • 29. June 10-11, 2008 Berlin, Germany Everything can be a bundle – Making OSGi bundles of Java legacy code Erik Wistrand wistrand@makewave.com Gunnar Ekolin ekolin@makewave.com