commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrey Tarantsov <>
Subject Javaflow & OSGi: success story
Date Sat, 31 May 2008 04:44:19 GMT

I found that the topic of Javaflow + OSGi has been raised on

  mailing list in the past. I decided this might still be interesting  
for someone, and that this is the most appropriate list for such info.

I don't know if any answers have been posted, so I wanted to share  
that I successfully got it to work, based on the following three  

1) article at
2) article at
3) Emma instrumentation hook sources at

I'm willing to share the sources with anyone interested. (Just too  
lazy to publish them right now, after a full night of debugging.)

Here's the README.txt accompanying my sources:

Using Apache Commons Javaflow with OSGi

Run-time code instrumentation required by Javaflow can be employed in  
OSGi environment
by means of so-called Adaptor Hooks. Please see [1] for more  
information on them.

Enabling Javaflow instrumentation

To instrument plugin classes with Javaflow, add the following header  
into the
bundle manifest file (META-INF/MANIFEST.MF): “JavaFlow-Enabled: true”.

Running with Javaflow

Please refer to [1]. In short, for *development* mode:

1) Open “Plug-ins” view, find org.eclipse.osgi and choose “Import As >  
Source Project”.

2) Make sure org.eclipse.osgi (from your workspace) and  
are enabled in the launch configuration.

3) Make extra sure org.eclipse.osgi and com.yoursway.osgi.javaflow are  
in the same file system directory (e.g. both in the workspace folder).

4) Add “-Dosgi.framework.extensions=com.yoursway.osgi.javaflow” to VM  
arguments of
your launch configuration (found on Arguments tab).

For *production* (compiled & jared plugins) mode:

1) Compile com.yoursway.osgi.javaflow into a jar, and make sure the  
jar includes
a version number (e.g. com.yoursway.osgi.javaflow_1.0.0.jar).

2) Put com.yoursway.osgi.javaflow_*.jar into eclipse/plugins folder  
(i.e. into
exactly the same folder where org.eclipse.osgi_*.jar is located).

3) Add “osgi.framework.extensions=com.yoursway.osgi.javaflow” to  

Failure to do any of these steps will cause Javaflow extension to be  
ignored. In case you find yourself debugging it, two places of  
interest are:

- org.eclipse.equinox.launcher/ 
(Reads extensions list from “osgi.framework.extensions” property and  
sets up
the class path of the system bundle. The same property is read from  
numerous other
location, but those locations do not affect anything loaded from the  

- org.eclipse.osgi/ 
(Actually reads the list of hook configurators from

A few facts

1) To provide run-time instrumentation, you need adaptor hooks.

2) Adaptor hooks can only be registered in OSGi extension bundles [2]

3) OSGi extension bundles cannot require any other bundles

4) So you need to put Javaflow libraries into the extension bundle  

5) To make Javaflow available to other plugins, they must import the  
rather than requiring the bundle (something you cannot do with  

6) Unfortunately, Eclipse PDE has some kind of problem importing the  
from com.yoursway.osgi.javaflow fragment — I could not get it to  

7) So you have to put another copy of Javaflow into a regular plugin,  
require it in a regular way. You end up with two copies of Javaflow,  
one of
them is only used for instrumentation so it's not a problem.

8) Equinox launcher reads to determine the  
extension classpath
(in case you wonder why the file is needed).


[2] OSGi R4 Core Reference, Section 3.15 “Extension Bundles”

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message