Unable to resolve bundle because offilter:="(&(osgi.wiring.package=org.slf4j)(version>=2.0.0)(!(version>=3.0.0)))"

43 Views Asked by At

I'm trying to ran Karaf 4.4.3 with my app which is using Log4j2 v2.22.1. However, I got and exception:

Caused by: org.apache.felix.resolver.reason.ReasonException: Unable to resolve com.my.bundle/4.1.0.SNAPSHOT: missing requirement [com.my.bundle/4.1.0.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=org.slf4j)(version>=2.0.0)(!(version>=3.0.0)))"

What I have already checked. I have pax-logging libraries in system directory:

$ find . | grep pax-logging
./system/org/ops4j/pax/logging/pax-logging-log4j2
./system/org/ops4j/pax/logging/pax-logging-log4j2/2.2.0
./system/org/ops4j/pax/logging/pax-logging-log4j2/2.2.0/pax-logging-log4j2-2.2.0.jar
./system/org/ops4j/pax/logging/pax-logging-api
./system/org/ops4j/pax/logging/pax-logging-api/2.2.0
./system/org/ops4j/pax/logging/pax-logging-api/2.2.0/pax-logging-api-2.2.0.jar
./system/org/ops4j/pax/logging/pax-logging-logback
./system/org/ops4j/pax/logging/pax-logging-logback/2.2.0
./system/org/ops4j/pax/logging/pax-logging-logback/2.2.0/pax-logging-logback-2.2.0.jar

My etc/startup.properties looks good having pax-logging entries:

mvn\:org.ops4j.pax.logging/pax-logging-api/2.2.0 = 8
mvn\:org.ops4j.pax.logging/pax-logging-log4j2/2.2.0 = 8

Also, I checked a compatibility table on pax-logging github page (https://github.com/ops4j/org.ops4j.pax.logging), seems pax-logging 2.2.0 is compatible with log4j2 2.22.1.

I found a similar question on stackoverflow but it didn't help me (karaf / filter:="(&(osgi.wiring.package=org.apache.logging.log4j)(version>=2.17.0)).

Did I miss anything else?

2

There are 2 best solutions below

0
NorrtT On

I found a solution but it's quite strange, if anyone can explain, it would be good.

Pax-logging 2.2.0 which is native for Karaf 4.4.3 exports org.slf4j v1.8 in its MANIFEST; however, log4j2 2.22.1 requires [2.0.0; 3.0.0) as mentioned in the Karaf log. It looks like log4j2 2.22.1 is not compatible with pax-logging 2.2.0 but github pax-logging page says it should be. I updated pax-logging from 2.2.0 to 2.2.6 which exports org.slf4j 2.0.6 and I can start Karaf. Probably, it would be better to downgrade log4j2.

0
Grzegorz Grzybek On

Pax Logging is very old OSGi library designed to make logging easier in OSGi environments. It's main goal was to allow users simply to use well known Logging facades (like SLF4J's LoggerFactory.getLogger()) without cumbersome OSGi Logging api (service tracking...).

Over time, Pax Logging allowed to use multiple logging facades (SLF4J, JUL, Commons Logging, JBoss Logging, Avalon Logging, Log4J1/2 API) while all logging went to single logging backend (Log4J1, Logback, Log4J2 (in order of appearance)).

Pax Logging started exporting SLF4J 2 packages since this change. It doesn't impact the implementation (still you choose between Log4j2 and Logback), but it simply allows to run bundles that were compiled with SLF4J2 (where maven-bundle-plugin generated Import-Package: org.slf4j;version="[2.0,3.0)").

So using Pax Logging is a good choice in any OSGi environment - and that's what Karaf is doing for ages.