Christophe Bouhier
Christophe Bouhier

Reputation: 224

Karaf and Eclipse Equinox OSGI services

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:

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");      
          }
    }
}

Upvotes: 0

Views: 1334

Answers (1)

Christian Schneider
Christian Schneider

Reputation: 19626

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.

Upvotes: 2

Related Questions