I'm currently working at a project where I need to transfer PDE style plugins to bnd style plugins. I ran into the problem with external jars so I build up bundles for every jar and included them to the build path. For most of the jars this worked fine but I got one which don't behave as expected.
The org.apache.commons.codec.language. This package comes from the jar org.apache.commons.codec and it resolves fine (at least for bndtools) but when I run the bundle I get the following error:
! could not resolve the bundles: [test-0.0.0 org.osgi.framework.BundleException: Could not resolve module: test [1]
Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"
]
! Failed to start bundle test-0.0.0, exception Could not resolve module: test [1]
Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"
org.osgi.framework.BundleException: Could not resolve module: test [1]
Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"
at org.eclipse.osgi.container.Module.start(Module.java:447)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:431)
at aQute.launcher.Launcher.startBundles(Launcher.java:519)
at aQute.launcher.Launcher.activate(Launcher.java:425)
at aQute.launcher.Launcher.run(Launcher.java:303)
at aQute.launcher.Launcher.main(Launcher.java:149)
In this github repo I extracted one that produces an error as a reference: https://github.com/MaPhil/osgi-externals-test
I googled quite a lot about this topic but the most answers seems to be around liferay or other specific libraries. I hope anyone of you can give me a hint.
Some good news to start with:
Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"
This indicates that your OSGi bundle has an import for org.apache.commons.codec.language
, and the fact that it has a version range (1.9 up to but not including 2.0) is a good indication that your build path isn't completely messed up.
Looking at your example workspace I see that you have a project which you're using to wrap the Apache Commons Codec library. I'm somewhat confused as to why you're doing this, as Apache Commons Codec is already natively available as an OSGi bundle. If you want to depend on it in your workspace you can simply add it to one of your existing repositories. For example in /cnf/central.maven
you could add:
commons-codec:commons-codec:1.9
Which would reference the official release from Maven Central. You can then reference this bundle in your bnd file's build path using:
-buildpath: org.apache.commons.codec
To run your application you should really create a bndrun
file which you can use to declare your requirements (in this case a requirement on your test project) and then use a Resolve
operation (either a button in Bndtools or a Gradle task). This will take your list of -runrequirements
and create a list of -runbundles
. It will end up looking something like this:
-runrequirements: osgi.identity;filter:='(osgi.identity=test)'
-runfw: org.eclipse.osgi;version='[3.13.100.v20180827-1536,3.13.100.v20180827-1536]'
-runbundles: test;version="[0.0.0,0.0.1)",\
org.apache.commons.codec;version="[1.9.0,1.9.1)"
You can then run directly from that bndrun file. It will start the framework and deploy all of the runbundles for you. If you use Bndtools then it will even keep the deployed bundles in sync with your Eclipse Workspace so that you always have the latest code deployed.
You can see some more information about how to do this sort of thing in the Bndtools documentation or related details in OSGi enRoute