Search code examples
eclipseosgircp

Bundle was not resolved because of a uses contraint violation


I introduced a 3rd party plugin into my existing Eclipse RCP application and now my logging no longer works. It seems that it's using it's own version of slf4j. How can I resolve this and have my slf4j and the one in the 3rd party jar co-exist in harmony?

  Bundle was not resolved because of a uses contraint violation.
    org.osgi.service.resolver.ResolutionException: Uses constraint violation. 
    Unable to resolve resource My3rdPartyLib.my3rdPartyLib_api [osgi.identity; 
    osgi.identity="My3rdPartyLib.my3rdPartyLib_api"; type="osgi.bundle"; 
    version:Version="2.4"] because it is exposed to package 'org.slf4j' 
    from resources slf4j.api [osgi.identity; osgi.identity="slf4j.api"; 
    type="osgi.bundle"; version:Version="1.7.21"] and activemq-all 
    [osgi.identity; osgi.identity="activemq-all"; type="osgi.bundle"; 
    version:Version="5.9.0"] via two dependency chains.

Chain 1:
  My3rdPartyLib.my3rdPartyLib_api [osgi.identity; 
   osgi.identity="My3rdPartyLib.my3rdPartyLib_api"; type="osgi.bundle"; 
   version:Version="2.4"]
    import: (osgi.wiring.package=org.slf4j)
     |
    export: osgi.wiring.package: org.slf4j
  slf4j.api [osgi.identity; osgi.identity="slf4j.api"; 
   type="osgi.bundle"; version:Version="1.7.21"]

Chain 2:
  My3rdPartyLib.my3rdPartyLib_api [osgi.identity; 
   osgi.identity="My3rdPartyLib.my3rdPartyLib_api"; type="osgi.bundle"; 
   version:Version="2.4"]
    import: (osgi.wiring.package=org.apache.activemq)
     |
    export: osgi.wiring.package: org.apache.activemq; uses:=org.slf4j
    export: osgi.wiring.package=org.slf4j
  activemq-all [osgi.identity; osgi.identity="activemq-all"; 
   type="osgi.bundle"; version:Version="5.9.0"]
    at org.eclipse.osgi.container.Module.start(Module.java:434)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1561)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

I tried including it as an RCP plugin. In the target->content view I checkmark the 3rd party jar and its necessary dependencies. I checkmark the slf4j jars that I need as well. If I run the product->validation it says 'no problems detected'. When I run it, it blows up with the message shown above.

Any help would be appreciated!


Solution

  • Why is My3rdPartyLib.my3rdPartyLib_api exporting slf4j.api? Perhaps you can change it to just import it. You don't show whether activemq-all also exports slf4j.api. One idea maybe not to use activemq-all but instead use the individual activemq parts you need. -all bundles can be convenient but their package together in an uber bundle can fix certain constraints which upset other parts of the system.