Search code examples
osgiapache-servicemixapache-zest

qi4j on osgi fails to bootstrap


Did anybody manage to get qi4j running on OSGi environment like servicemix? I tried without success. It constantly tells me that:

[Application(6)] The activate method has thrown an exception
org.qi4j.bootstrap.BootstrapException: Can not create Qi4j without a 
    Qi4j Runtime.
at org.qi4j.bootstrap.Energy4Java.<init>(Energy4Java.java:51)
at org.qi4j.bootstrap.Energy4Java.<init>(Energy4Java.java:44)
...

On karaf console, the following is printed:

Qi4j Runtime jar is not present in the classpath.

I'm bootstrapping qi4j in an activator method like so (apache scr component):

@Activate
public void activate() {

    try {
        // Bootstrap Qi4j Runtime
        // Create a Qi4j Runtime
        qi4j = new Energy4Java();
        ...
    } ...

In pom.xml I'm defining the imports:

<Import-Package>
    org.qi4j.runtime,
    org.qi4j.runtime.*,
    org.qi4j.api.activation,
    org.qi4j.bootstrap,
    org.slf4j, 
    *
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>

All packages resolve, including the runtime which I deployed in servicemix 5.3.0 together with needed dependencied:

features:install scr
osgi:install wrap:mvn:org.codeartisans/org.json/20130213
osgi:install mvn:org.ow2.asm/asm-all/4.1
osgi:install mvn:org.qi4j.core/org.qi4j.core.api/2.0
osgi:install mvn:org.qi4j.core/org.qi4j.core.functional/2.0
osgi:install mvn:org.qi4j.core/org.qi4j.core.io/2.0
osgi:install mvn:org.qi4j.core/org.qi4j.core.spi/2.0
osgi:install mvn:org.qi4j.core/org.qi4j.core.bootstrap/2.0
osgi:install mvn:org.qi4j.core/org.qi4j.core.runtime/2.0

What's the trick?


Solution

  • Actually I debugged the runtime creation process and found that the RuntimeFactory in bootstrap bundle tries to load org.qi4j.runtime.Qi4jRuntimeImpl. Obviously this comes from org.q14j.runtime package which isn't imported by the bootstrap bundle.

    I created a fragment bundle for host org.qi4j.core.bootstrap;bundle-version=2.0.0 to fix the imports.

    This did the job.