0

我想创建一个 Web 应用程序,它在 OSGI 框架内执行某种捆绑活动的某种动画。我正在通过 Servletbridge 使用嵌入在 Tomcat 中的 Equinox。我试图创建一个使用 httpservice 注册 HTML 页面(带有小程序标签)的 OSGI 包。OSGI 包包含一个带有小程序类的包。

当我在 tomcat/webapps/bridge/WEB-INF/eclipse/plugin 目录中导出插件项目时,jar 内容为:

META-INF
META-INF/MANIFEST.MF
name/of/packages/.class files
home.html

在这个包的激活器类中,我得到一个 httpservice 并将 home.html 文件注册为 /home。当我启动Tomcat并转到:

localhost:8080/bridge/home 

页面加载,但我ClassNotFoundException在小程序上得到一个,而从 Jar 存档打开 HTML 页面小程序加载。我怎样才能让它工作?

编辑:home.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<applet code="thesis.bot.wab.applet.DApplet.class" width="400" height="250"></applet>
</body>
</html>

src/thesis.bot.wab.Activator

public class Activator implements BundleActivator {
private static boolean started=false;
HttpServiceTracker http;

public void start(BundleContext context) throws Exception {
    System.out.println("started");
    http = new HttpServiceTracker(context);
    http.open();
    started=true;
}

public void stop(BundleContext context) throws Exception {
    System.out.println("stopped");
    started=false;
    http.close();
}

public static boolean isStarted(){
    return started;
}

private class HttpServiceTracker extends ServiceTracker {

    public HttpServiceTracker(BundleContext context) {
        super(context, HttpService.class.getName(), null);
    }

public Object addingService(ServiceReference reference) {
   HttpService httpService = (HttpService) context.getService(reference);
    try {   
    httpService.registerResources("/home", "/home.html", null);
    httpService.registerServlet("/servlet", new DServlet(context), null, null);
    } 
            catch (Exception e) {
            e.printStackTrace();
            }
return httpService;
}       

public void removedService(ServiceReference reference, Object service) {
    HttpService httpService = (HttpService) service;
    httpService.unregister("/servlet"); //$NON-NLS-1$
    httpService.unregister("/home");
    super.removedService(reference, service);
        }
    }
}

编辑:我的目的是检索 bundlecontext 并获取有关 bundle 的信息以在小程序中可视化它们。

4

1 回答 1

0

首先,您的浏览器会下载 html 文件。下载后,浏览器会检查 html 中的 applet 标签。它启动一个尝试从 url 下载小程序的 JVM:

http://localhost:8080/bridge/thesis.bot.wab.applet.DApplet.class

然而,什么都没有,为什么会有什么?

您应该将类​​文件或完整的 jar 文件注册为资源。之后,您应该在指向 jar 或类文件的 html 文件中插入一个 applet 标记。如果您的小程序有任何依赖项,那么这些 jar 文件也应该被列出。

打开 Java 控制台(谷歌为它)并按下按钮“5”以获得低级调试消息很有用。在那里您会看到为什么您的小程序无法启动(下载 url、依赖问题...)

于 2013-10-14T21:16:39.643 回答