1

我正在尝试使用 BndTools 构建一个 servlet。我遵循了本教程:http ://www.ralfebert.de/archive/java/osgi_server/

但是..我无法让servlet工作:(。问题是apache felix白板包给出了调试消息:忽略Servlet服务[javax.servlet.Servlet],别名丢失或为空

我已经用谷歌搜索了几个小时,但我无法得到这个问题的任何答案。当我尝试访问 localhost:8080 时,我收到以下消息:

访问 / 时出现问题。原因:

NOT_FOUND

这是我的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!");
    }

}

我错过了什么或者我做错了什么?

这是我的 bnd.bnd 文件的来源:

-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]'

而且因为我使用的是更高版本的 BndTools,我无法再管理 .bnd 文件中的所有内容。所以这里也是我的 run.runbnd 文件的来源:

-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
4

1 回答 1

2

您需要将提供声明式服务的服务组件运行时的包添加到您的运行配置中。该包名为 org.apache.felix.scr,可以在存储库视图的 Bndtools Hub 存储库中找到。

您完美地配置了组件,但您需要一个 SCR 包来在运行时实际处理配置。

于 2013-12-09T17:48:29.083 回答