Reputation: 2159
I'm running into a really annoying issue while trying to get an OSGi program setup while also using the AWS SDK for Java. I'm using Eclipse with Bndtools and have created about as basic of a project as I can. All I have to do is import any part of the AWS SDK and I start getting a couple of errors that I can't seem to get around.
For starters, my test class is below:
package com.test;
import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleContext;
import com.amazonaws.auth.BasicAWSCredentials;
public class Test extends DependencyActivatorBase {
BasicAWSCredentials creds;
public Test() {
}
@Override
public void init(BundleContext arg0, DependencyManager arg1) throws Exception {
arg1.add(createComponent().setInterface(Object.class.getName(), null).setImplementation(Test.class));
}
}
I then create a Bundle descriptor and add com.test
to the private packages section. Under the bnd.bnd
I have osgi.cmpn
,osgi.core
,org.apache.felix.dependencymanager
, and com.amazonaws.aws-java-sdk-osgi
in the build path. The AWS SDK bundle I got from the Maven Repository and added all of the dependencies specified on that page to the local repo, as well. I then create a Run descriptor and it instantly gives the following error when attempting to resolve after adding myTest.testbundle
to the run requirements:
Unable to resolve <<INITIAL>> version=null:
missing requirement Require[osgi.identity]{}{filter=(osgi.identity=myTest.testbundle)} [caused by:
Unable to resolve myTest.testbundle version=0.0.0:
missing requirement Require[osgi.wiring.package]{}{filter=(&(osgi.wiring.package=com.amazonaws.auth)(version>=1.9.0)(!(version>=2.0.0)))} [caused by:
Unable to resolve com.amazonaws.aws-java-sdk-osgi version=1.9.36:
missing requirement Require[osgi.wiring.package]{}{filter=(osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp)}]]
I saw something in another post that stated that only java.*
packages are included in the OSGi environment, so even though jaxp is part of the Java runtime library, I would have to specifically import it. So I looked for an OSGi bundle of the library and found it in the Maven Repository again, downloaded, and added it to my local repo. This fixes the resolve error, but now I get the following error when I click Run OSGi in the Run Descriptor:
! could not resolve the bundles: [com.amazonaws.aws-java-sdk-osgi-1.9.36Unresolved constraint in bundle com.amazonaws.aws-java-sdk-osgi [1]: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]
, myTest.testbundle-0.0.0Unresolved constraint in bundle myTest.testbundle [7]: Unable to resolve 7.0: missing requirement [7.0] osgi.wiring.package; (&(osgi.wiring.package=com.amazonaws.auth)(version>=1.9.0)(!(version>=2.0.0))) [caused by: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]]
, org.apache.servicemix.bundles.jaxp-ri-1.4.5.1Unresolved constraint in bundle org.apache.servicemix.bundles.jaxp-ri [16]: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)
]
! Failed to start bundle com.amazonaws.aws-java-sdk-osgi-1.9.36, exception Unresolved constraint in bundle com.amazonaws.aws-java-sdk-osgi [1]: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]
! Failed to start bundle myTest.testbundle-0.0.0, exception Unresolved constraint in bundle myTest.testbundle [7]: Unable to resolve 7.0: missing requirement [7.0] osgi.wiring.package; (&(osgi.wiring.package=com.amazonaws.auth)(version>=1.9.0)(!(version>=2.0.0))) [caused by: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]]
! Failed to start bundle org.apache.servicemix.bundles.jaxp-ri-1.4.5.1, exception Unresolved constraint in bundle org.apache.servicemix.bundles.jaxp-ri [16]: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)
If I comment out the lines referring to the AWS components in the test code, the errors disappear. I'm about at my whits end trying to figure out what I need to do to fix this issue. The Run descriptor I'm using was created using the default settings, so it runs on org.apache.felix.framework;version='[4,5)'
but I changed it to run under a JavaSE-1.8 environment instead of 1.7.
Looking at the issue and a few other posts related to it, it appears I need to explicitly tell it to import the org.w3c.dom
library into the OSGi environment, but I'm not quite sure how to do that when running it from Eclipse via Bndtools, or if doing this will even fix the issue.
Upvotes: 2
Views: 1318
Reputation: 2159
I finally figured out how to add the JRE packages that were missing. Inside the Bndtools Run Descriptor
, I clicked on Source and added the following:
-runsystempackages: \
org.w3c.dom.html,\org.w3c.dom.ranges,\org.w3c.dom.traversal
Now my OSGi framework launches and runs the Test
class in the OP without error! I originally added only the org.w3c.dom.html
, but this then caused the other 2 to pop an error, so I added them.
Note: You'll need to stop and restart the framework for this change to take effect.
Upvotes: 1