0

In a series of blogs on Java webframeworks, which should play nicely in OSGI, I am taking a close look at Karaf. My test case is pretty straight-forward, deploy a Servlet on Karaf. There are different HTTPService implementations for OSGI, I am trying with the Equinox implementation (org.eclipse.osgi.services).

My bundle loads nicely without the HTTPService dependencies, but when I add dependencies for HTTPService [3], Servlet and try to install the feature [1], I run into trouble [2].

Notes:

  • The HTTP service itself is installed using OSGI DS services [3]
  • Karaf is configured to use Equinox OSGI impl.

So the complaint is about aries-blueprint, but I don't have a depedency on it in the bundle I am trying to install.

Advise from the community would be most welcome!

Thank You, Christophe Bouhier

[1] The Karaf feature named oss2

<?xml version="1.0" encoding="UTF-8"?>
<features name="oss2-features" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
  <feature name="oss2" version="1.0.0">
    <bundle>file:///Users/Christophe/Documents/Projects/GIT_netxstudio/plugins/base/com.netxforge.oss2.web/target/com.netxforge.oss2.web-1.0.0-SNAPSHOT.jar</bundle>
    <bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/javax.servlet_3.0.0.v201112011016.jar</bundle>
    <bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.osgi.services_3.3.100.v20130513-1956.jar</bundle>
    <bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.osgi_3.9.1.v20140110-1610.jar</bundle>
    <bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.equinox.transforms.hook_1.0.401.v20130327-1442.jar</bundle>
    <bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.equinox.weaving.hook_1.0.200.v20130327-1442.jar</bundle>
  </feature>
</features>

[2] the error:

karaf@root(bundle)> feature:install oss2
Error executing command: Uses constraint violation. Unable to resolve resource org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.1] because it is exposed to package 'org.osgi.service.framework' from resources org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610] and org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610] via two dependency chains.

Chain 1:
  org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.1]
    import: (osgi.wiring.package=org.osgi.service.framework)
     |
    export: osgi.wiring.package: org.osgi.service.framework
  org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610]

Chain 2:
  org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.1]
    import: (&(osgi.wiring.package=org.apache.aries.util.tracker)(version>=1.0.0)(!(version>=2.0.0)))
     |
    export: osgi.wiring.package=org.apache.aries.util.tracker; uses:=org.osgi.service.framework
  org.apache.aries.util [org.apache.aries.util/1.1.0]
    import: (&(osgi.wiring.package=org.osgi.service.framework)(version>=1.0.0)(!(version>=2.0.0)))
     |
    export: osgi.wiring.package: org.osgi.service.framework
  org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610]

[3] Service

@Component
public class WebDude{

    private HttpService httpService;

    @Activate
    public void activate() {
        try {
            httpService.registerServlet("/dudeme", new WebDudeServlet(), null, null);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    @Reference
    public void setHTTPService(HttpService httpService) {
        this.httpService = httpService;
    }

    class WebDudeServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;

        @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.getWriter().write("I am dude");      
          }
    }
}
Christophe Bouhier
  • 224
  • 1
  • 5
  • 14

1 Answers1

2

You are installing org.eclipse.osgi_3.9.1.v20140110-1610.jar which is an OSGi framework itself. You should never install a framework bundle into an existing framework.

Instead switch karaf to use equinox. In etc/config.properties set:

karaf.framework=equinox

Then leave out the above bundle from your feature file. You can even make the feature smaller by using the karaf features for the HttpService and DS:

features:install scr http

So perhaps after that you can directly install your own bundle.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • As I state in the question, Karaf is already configured for Equinox. Also I figured installing org.eclipse.osgi could be a problem, so I tried to leave it out and I get the exact same error. Regarding features:install scr http. I could do so, but the whole purpose it to make it work with the equinox HTTPService implementation. Has this been done by anyone? Also my question is initially, how to read and understand the error message. What's the relation with Apache Aries? – Christophe Bouhier Oct 21 '14 at 06:02
  • 1
    The message means that the bundle org.apache.aries.blueprint.core can not be resolved as the bundles you install introduce conflicting exports of the same package. This happens as the blueprint bundle is already installed and karaf tries to resolve it again with the new bundles that are available after the feature install. – Christian Schneider Oct 21 '14 at 13:03