OSGi + Logback + slf4j - Eclipse Launch Configuration

Here is my configuration:

We are developing an OSGi application and want to enable logging. I decided to use slf4j + logback.

We use Eclipse as an IDE and Tycho to use the Eclipse IDE, such as Manifest Editor, etc.

So, I tried the following:

A new plugin has been created 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 go to Run -> Run Configurations -> OSGi Framework and select my Bundle and click "Add necessary plugins", more than 100 packs will be selected, and I get a lot of errors and exceptions.

So, I came up with a new plugin from existing Jars, which includes the following three banks:

  • Logback-classic-1.0.7
  • Logback-core-1.0.7
  • com.springsource.slf4j.api-1.6.1 (I don't believe this is a good idea, but hey ...)

If I create a new launch configuration manually (without clicking "add the necessary packages", it works as expected, but as far as I click "add the necessary packages", I return to more than 100 links with a lot of errors (some Jetty, for example. ..)

So my question is: how to enable logback and slf4j in my OSGi application and use it in eclipse and configure it correctly?

If you need more information, feel free to ask.

+7
source share
4 answers

AFAIK there are some problems in the header of the package manifest in the current official Logback / SLF4J bars. However, you only need the following three banks / packs. Basic functionality does not require others.

  • API SLF4J
  • The core of the magazine
  • Classic magazine

At Eclipse, we put packages in Orbit for reuse in projects. We apply some changes to the manifest header, which we think are useful. For example, we pass the actual SLF4J binding as a fragment to avoid circular dependency of the original SLF4J API bar.

Here are the links to download in packages:

You also can:

Please note that "Add required plugins" is not smart enough. He can choose too many or too few plugins. Sometimes the service API is supplied in one set, but the actual implementation of the service comes in a second set. He cannot choose this kit.

+8
source

There is a flag that says "Allow additional import." It is by default, but it almost always leads to the described behavior that it wants to add everything.

Turning this feature off should help. In addition, PDE tends to add many fragments that are not needed.

In general, I rarely trust Eclipse with the addition of the "right" packages to run. I just use "validate" and add everything that is necessary manually, and check again. This may take several minutes, but figuring out what went wrong when you leave it in the PDE may take several hours.

+2
source

If you want to use it with Eclipse Equinox, you can try Eclipse-BuddyPolicy. This allows one plugin to load all classes from another plugin without importing it explicitly. This may solve your problem.

Add to your manifest from the jar kit:

Eclipse-BuddyPolicy: dependent

and to set using the magazine

Eclipse-RegisterBuddy: com.other.plugin

see http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fbundle_manifest.html

0
source

Not sure about logback, but you can also try pax logging . Just install the pax logging api and pax logging service and it should work. There is also documentation on customization in eclipse .

0
source

All Articles