我想创建一个 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 的信息以在小程序中可视化它们。