cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cristiano Ghersi <>
Subject Re: Cayenne under OSGi
Date Fri, 01 Feb 2013 09:49:17 GMT
Hi Andrus,

given your re-engineering of the structure, perhaps I can tell you the
changes we have plugged in in order to make the stuff work. They are quite
simple changes to the code, so perhaps is simpler for you to add these
pieces of code than trying to cope with the complete structure.

We just added ClassRegistry class in the *org.apache.cayenne.di.spi*
Moreover, the class *org.apache.cayenne.di.spi.DefaultAdhocObjectFactory* has
also been modified to be able to search in the ClassRegistry for classes:

public Class<?> getJavaClass(String className) throws ClassNotFoundException {

                // is there a better way to get array class from string name?

                if (className == null) {
                        throw new ClassNotFoundException("Null class name");

                ClassLoader classLoader =

                if (classLoader == null) {
                        classLoader =

                //first for OSGi Environment: look for class in registry.
                //try with the class loader registry
                Class<?> registryClass =
                if (registryClass != null) {
                        try {
                        catch (ClassNotFoundException cnfe) {

                // use custom logic on failure only, assuming
primitives and arrays are not that
                // common
                try {
                        return Class.forName(className, true, classLoader);

                if (!className.endsWith("[]")) {
                        if ("byte".equals(className)) {
                                return Byte.TYPE;

Generate an OSGi Bundle

To generate an OSGi bundle some changes are needed in the *pom.xml*.
First of all it is necessary to change the *packaging* type of the
project from *jar* to *bundle* as it is show in this snippet:

<project xmlns=""
        <name>Cayenne OSGified</name>
<packaging>bundle</packaging>  <url></url>

Then it is necessary to add a *plugin* to the *build* section:



Finally you can generate the bundle jar

$ cd cayenne-osgi # or navigate to the root directory of the cayenne
osgi project
$ mvn org.apache.felix:maven-bundle-plugin:bundle

The bundle jar can be found in *cayenne-osgi/target/cayenne-osgi.jar.*



To use the Cayenne OSGi bundle the following steps must be performed:

   1. Import the .jar bundle generated with the above procedure
   2. Create and import a Cayenne *dependencies* bundle containing all the
   .jar files needed to satisfy the import packages of Cayenne bundle (the
   ones added to folder Cayenne-Dependencies folder in the github repo)
   3. Create a Fragment bundle (setting as the host Cayenne bundle) for
   each cayenne project. In the *src* folder of the fragment add the two
   cayenne xml files.

Hope this can help the integration.

Let me know if you need further clarification, I'm at complete disposal.


2013/2/1 Andrus Adamchik <>

> Hi cghersi,
> Thanks!
> Trying to make sense of the GitHub project structure and what is different
> from Cayenne. From what I can tell we need this piece in the pom:
>         <plugin>
>                 <groupId>org.apache.felix</groupId>
>                 <artifactId>maven-bundle-plugin</artifactId>
>                 <version>2.3.7</version>
>                 <extensions>true</extensions>
>                 <configuration>
>                         <instructions>
>                                 <Export-Package>org.apache.cayenne,
> org.apache.cayenne.*</Export-Package>
> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
>                         </instructions>
>                 </configuration>
>         </plugin>
> and also the META-INF dir (
> ?
> Or is META-INF generated?
> Also integrating this into our convoluted build structure will be a
> challenge. One of the 3.2 undeclared goals is simplifying the build
> structure, so maybe once we start looking into it, we might consider the
> OSGi aspect. And in any event it is very helpful for us, even we can't
> simply patch Cayenne from what's on the GitHub. It gives a clear idea of
> what we need to do to make ours jars OSGi-friendly.
> Cheers,
> Andrus
> On Jan 31, 2013, at 3:42 PM, Cristiano Ghersi <
>> wrote:
> > Good morning,
> >
> > My company (Abodata, has ported Cayenne into OSGi
> > environment, and we would like to contribute to Cayenne project with this
> > enhancement as I posted under user mailing list on October 2012.
> >
> > Following your instructions, we have uploaded the full content under the
> > github repo:
> >
> >
> > Basically, we have packaged the source code of 3.1 version into an OSGi
> > bundle called cayenne-osgi, adding some stuff to manage the particular
> > classloading features of OSGi.
> > Then we added also another bundle, called Cayenne-3.1-Dependencies, that
> > packages all the required dependencies.
> >
> > I'm at complete disposal for every clarification you need.
> >
> > I'll wait for your feedback.
> >
> > Best
> > cghersi

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