Problems with buidling a servlet using apache felix whiteboard (OSGi)

1.5k views Asked by At

I'm trying to build a servlet using BndTools. I followed this tutorial: http://www.ralfebert.de/archive/java/osgi_server/

But.. I can't get the servlet to work :(. The problem is that the apache felix whiteboard bundle gives a debug message: Ignoring Servlet Service [javax.servlet.Servlet], alias is missing or empty

I've googled around for hours and hours but I can't get any answers to this problem. When I try to access localhost:8080 I get the following message:

Problem accessing /. Reason:

NOT_FOUND

Here's the code of my servlet:

package com.example.helloworld;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.*;

import aQute.bnd.annotation.component.Component;

@Component(provide=Servlet.class, properties = { "alias=/" })
public class HelloWorldServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.getWriter().append("Hello World!");
    }

}

What am I missing or am I doing something wrong??

Here's the source of my bnd.bnd file:

-buildpath: osgi.core,\
    osgi.cmpn,\
    biz.aQute.bnd.annotation,\
    junit.osgi,\
    org.apache.felix.http.jetty
-sub: *.bnd
-runfw: org.apache.felix.framework;version='[4.0.3,4.0.3]'

And because I'm using a later version of BndTools, I can't manage everything in the .bnd file anymore. So here's the source of my run.runbnd file also:

-runfw: org.apache.felix.framework;version='[4,5)'
-runee: JavaSE-1.6
-runsystemcapabilities: ${native_capability}

-resolve.effective: active



-runrequires: osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.runtime)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.http.jetty)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.webconsole)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.http.whiteboard)'
-runbundles: org.apache.felix.gogo.command,\
    org.apache.felix.gogo.runtime,\
    org.apache.felix.gogo.shell,\
    osgi.cmpn,\
    org.apache.felix.http.jetty,\
    org.apache.felix.http.whiteboard,\
    com.example.helloworld.org.example;version=latest
1

There are 1 answers

0
Arie van Wijngaarden On BEST ANSWER

You need to add the bundle providing the service component runtime of the declarative services to your run configuration. The bundle is called org.apache.felix.scr and can be found in the Bndtools Hub repository in the repository view.

You configured your component perfectly, but you need a SCR bundle to actually process the configuration at run-time.