Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGi + Logback + slf4j - Eclipse Run Configuration

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:

  • logback-classic-1.0.7
  • logback-core-1.0.7
  • com.springsource.slf4j.api-1.6.1 (I dont believe this is a good idea, but hey...)

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.

like image 834
hueck Avatar asked Nov 27 '12 16:11

hueck


2 Answers

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.

  • SLF4J API
  • Logback Core
  • Logback Classic

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:

  • org.slf4j.api
  • ch.qos.logback.core
  • ch.qos.logback.classic
  • ch.qos.logback.slf4j

You may also want:

  • org.slf4j.ext
  • org.slf4j.jcl (Commons Logging via SLF4J)
  • org.slf4j.jul (Java Logging Bridge)
  • org.slf4j.log4j (LOG4J via SLF4J)

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.

like image 102
Gunnar Avatar answered Nov 11 '22 08:11

Gunnar


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.

like image 2
Frank Lee Avatar answered Nov 11 '22 07:11

Frank Lee