1

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?

рüффп
  • 5,172
  • 34
  • 67
  • 113
Sahlix
  • 11
  • 2
  • 1
    Qi4j is now Apache Zest and we welcome contributors with open arms. I have created https://issues.apache.org/jira/browse/ZEST-131 to track this. – Niclas Hedhman Dec 12 '15 at 02:21

2 Answers2

1

Probably you haven't started the bundles. osgi:install installs the bundles but it doesn't start them. Please try this

features:install scr
osgi:install -s wrap:mvn:org.codeartisans/org.json/20130213
osgi:install -s mvn:org.ow2.asm/asm-all/4.1
osgi:install -s mvn:org.qi4j.core/org.qi4j.core.api/2.0
osgi:install -s mvn:org.qi4j.core/org.qi4j.core.functional/2.0
osgi:install -s mvn:org.qi4j.core/org.qi4j.core.io/2.0
osgi:install -s mvn:org.qi4j.core/org.qi4j.core.spi/2.0
osgi:install -s mvn:org.qi4j.core/org.qi4j.core.bootstrap/2.0
osgi:install -s mvn:org.qi4j.core/org.qi4j.core.runtime/2.0
KSobkowiak
  • 143
  • 6
  • Version 2.0 also didn't go through a proper validation for OSGi, as none of the core developers was working on OSGi at that time. For instance, it seems strange that joda-time isn't required and I would therefor not bet on it working. – Niclas Hedhman Jan 26 '15 at 23:55
0

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.

Sahlix
  • 11
  • 2
  • Of course it would be cleaner if the bootstrap bundle would import `org.q14j.runtime` directly. – Sahlix Jan 27 '15 at 08:33
  • There is still a ClassLoader issue when using the vanilla `Energy4Java` class. It's due to the use of `currentThread.getClassLoader()`. I worked around it by setting the classLoader to bundleClassLoader during bootstrap phase. – Sahlix Feb 02 '15 at 15:32
  • if you are still using Qi4j/Polygene, please contact me directly. niclas@hedhman.org – Niclas Hedhman Sep 25 '17 at 03:38