0
votes

I want to do the following solution:Apache Felix + Weld for Java SE. For that I want to run one of examples from weld archive - weld-osgi-paint. For now I have the following bunle list:

cdi-api.jar
ops4j-base-lang-1.5.0.jar
pax-swissbox-core-1.8.0.jar
weld-osgi-paint-core.jar
org.apache.felix.scr-1.8.2.jar
pax-swissbox-lifecycle-1.8.0.jar
weld-osgi-paint-square.jar
javax.annotation-api-1.2.jar
org.apache.servicemix.bundles.javax-inject-1_2.jar
pax-swissbox-tracker-1.8.0.jar
weld-osgi-paint-triangle.jar
javax.el-api-2.2.4.jar
pax-cdi-api-0.11.0.jar
slf4j-api-1.7.6.jar
xbean-bundleutils-4.1.jar
javax.interceptor-api-1.2.jar
pax-cdi-extension-0.11.0.jar
slf4j-log4j12-1.7.2.jar
log4j-1.2.17.jar
pax-cdi-spi-0.11.0.jar
weld-osgi-paint-api.jar
org.osgi.compendium-4.3.1.jar
org.osgi.core-4.3.1.jar

And I get the following:

org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision org.ops4j.pax.cdi.extension [9.0] because it is exposed to package 'org.osgi.framework' from bundle revisions org.apache.felix.framework [0] and osgi.core [2.0] via two dependency chains.

Chain 1: org.ops4j.pax.cdi.extension [9.0] import: (&(osgi.wiring.package=org.osgi.framework)(version>=1.7.0)(!(version>=2.0.0))) | export: osgi.wiring.package=org.osgi.framework org.apache.felix.framework [0]

Chain 2: org.ops4j.pax.cdi.extension [9.0] import: (&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5.0)(!(version>=2.0.0))) | export: osgi.wiring.package=org.osgi.util.tracker; uses:=org.osgi.framework osgi.cmpn [3.0] import: (osgi.wiring.package=org.osgi.framework) | export: osgi.wiring.package=org.osgi.framework osgi.core [2.0]

and this

... Caused by: java.lang.ClassCastException: org.apache.felix.scr.impl.Activator cannot be cast to org.osgi.framework.BundleActivator at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4177)

The problem, as I understand is that pax cdi needs org.osgi and it doesn't work with apache felix. How to solve such problem?

EDIT 1
Whem I don't install org.osgi.core I have the following exception, as org.osgi.service.packageadmin is in org.osgi.core.

org.osgi.framework.BundleException: Unresolved constraint in bundle org.ops4j.pax.cdi.extension [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (&(osgi.wiring.package=org.ops4j.pax.cdi.spi)(version>=0.11.0)(!(version>=1.0.0))) [caused by: Unable to resolve 9.0: missing requirement [9.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.xbean.osgi.bundle.util)(version>=3.18.0)(!(version>=5.0.0))) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.packageadmin)(version>=1.2.0)(!(version>=2.0.0)))]] at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826) at org.apache.felix.framework.Felix.startBundle(Felix.java:1868) at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944) at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:931) at com.techsenger.launcher.core.se.all.Launcher.startBundles(Launcher.java:146) at com.techsenger.launcher.core.se.all.Launcher.main(Launcher.java:60)

EDIT 2
I didn't say I use org.apache.felix.framework-4.0.3.jar. I solved the problem by removing org.osgi.core bundle as Christian Schneider said. After that I added necessary packages to system packages this way:

 String SYSTEM_PACKAGES = 
        "org.osgi.framework;version=\"1.8\"," + 
        "org.osgi.service.packageadmin;version=\"1.8\","+
        "org.osgi.framework.wiring;version=\"1.8\","+
        "javax.swing,javax.management,javax.naming,javax.xml.parsers,"+
        "org.w3c.dom,org.xml.sax,org.xml.sax.helpers";
        configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, SYSTEM_PACKAGES);

Besides I had to take version 0.8.0 of pax-cdi-* and some others. And this is what I got:

org.osgi.framework.BundleException: Unresolved constraint in bundle org.jboss.weld.examples.weld-osgi-paint-core [23]: Unable to resolve 23.0: missing requirement [23.0] osgi.extender; (osgi.extender=pax.cdi) at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826) at org.apache.felix.framework.Felix.startBundle(Felix.java:1868) at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944) at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:931)

How to fix it? I installed and started weld-se and weld-se-core but it didn't help.

1
I'm very surprised you got anywhere with only 10 packages exported by the system bundle. What about all the rest of the JavaSE packages?Neil Bartlett
@Neil Bartlett I don't understand you question. I need these packages to run wel example. They seem to be enough.user2022068
They may seem to be enough initially but what if you add more functionality? Anyway I don't really understand what you are doing because Felix already provides the package that you need...Neil Bartlett
@Neil Bartlett What I am doing now is to solve this problem - missing requirement [23.0] osgi.extender; (osgi.extender=pax.cdi). Do you know how to solve it? What does it mean?user2022068
It means that some bundle has declared a requirement for the "pax.cdi" extender, but you haven't installed the bundle that declares that it provides this extender. I don't know what bundle you need to install, sorry. Maybe ask on the PAX mailing list. Also please go back and sort out the packages because you're only going to hit bigger problems later.Neil Bartlett

1 Answers

3
votes

The problem is that org.osgi.core is installed. The packages provided by this jar are also provided by the felix framework. So simply do not install thecorg.osgi.core jar.

You also need to install the pax cdi bundles. Weld itself does not provide the osgi support you need for cdi.