Here is my configuration:
We are developing an OSGi application and want to include logging. I decided to use slf4j + logback.
We are using Eclipse as an IDE and Tycho to benefit from the Eclipse IDE like Manifest Editor and so on.
So I have tried the following:
Created a new plugin with the following Manifest.mf:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Createcommand
Bundle-SymbolicName: de.hswt.oms.ws.wsr.createcommand
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: de.hswt.oms.ws.command.wsr,
de.hswt.oms.ws.ds.core.data.impl,
org.slf4j
Service-Component: OSGI-INF/component.xml
Now when i move to Run -> Run Configurations -> OSGi Framework and select my Bundle and click "Add Required plugins" more than 100 Bundles will be selected and I get a lot of errors and exceptions.
So I came up with a new plugin from existing Jars which include the following three jars:
If I create a new run configuration manually (not clicking "add required bundles" it works as expected but as far as I click "add required bundles" I come back to the more then 100 Bundles with a lot of errors (some Jetty stuff for example...)
So my Question is: How can I enable logback and slf4j in my OSGi application and use it within eclipse and configure it properly?
If you need more information please feel free to ask.
AFAIK there are some issues in the bundle manifest header in the current official Logback/SLF4J jars. However, you only need the following three jars/bundles. No other are required for the basic functionality.
At Eclipse we put the bundles in Orbit for re-use across projects. We apply some modifications to the manifest header that we think are beneficial. For example, we deliver the actual SLF4J binding as a fragment to avoid the circular dependency of the original SLF4J API jar.
Here are the download links to the bundles:
You may also want:
Please note that "Add Required plugins" is not smart enough. It may select too many or too few plug-ins. Sometimes service API is delivered in one bundle but the actual service implementation is delivered in a second bundle. It may not select that bundle.
There is a checkbox saying something like 'Resolve optional imports'. It's on by default, but that pretty much always results in the behaviour you describe, that it wants to add everything.
Switching that off should help. also, PDE tends to add a lot of fragments that are not needed.
All in all, I rarely trust Eclipse with adding the 'right' bundles for runtime. I just use 'validate' and add whatever is needed manually, and check again. It might take a few minutes but figuring out what went wrong when you leave it to PDE can take hours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With