1

我计划从OSGi带有 Web 服务的 Android 开始,其中我将能够在 Android 浏览器上运行 Java Server Pages (jsp) 和 Java Servlet。

我的第一步是Knopflerfish在 Android 上安装。我从 knopflerfish 遵循了本教程:http ://www.knopflerfish.org/releases/5.0.0/docs/android_dalvik_tutorial.html

Knopflerfish 做得很好,我在 Android 手机的浏览器上看到了 localhost:8080。

我的第二步是安装Pax Web在也安装在 Android 上的 Knopflerfish 上。我也从这里遵循了他们的教程:http ://www.knopflerfish.org/kf_pax_web_tutorial.html

教程说:

卸载 KF HTTP 包

第一步是停止 HTTP 根包并卸载 JSDK 和 HTTP-server 包,因为 PaxWeb 将接管此功能。通常,您很可能还想卸载 HTTP-root-bundle,但在本教程中,我们将保留它的安装状态。确保在进行下一步之前刷新包。

然后:

安装 PaxWeb

第二步是从 PaxWeb 安装并启动以下包。

  • pax-web-jsp-1.0.2.jar(安装)
  • pax-web-jetty-bundle-1.0.2.jar(安装和启动)
  • pax-web-extender-war-0.8.0.jar(安装和启动)

捆绑包Pax Web已成功安装。


问题

Pax Web无法启动捆绑包。

当我尝试启动HTTP-root-IMP它是一个 Knopflerfish 包时,它在控制台上给了我这个错误消息。

[stderr] ## DEBUG: errors - FrameworkErrorEvent bundle #20
[stderr] ## DEBUG: errors - FrameworkErrorEvent throwable:
Couldn't start bundle: HTTP-root-IMPL (#20) (due to: org.osgi.framework.BundleException: Bundle#20, unable to resolve: Missing package(s) or can not resolve all of the them:
org.osgi.service.http;version=[1.1.0,2.0.0) -- Could not resolve exporting bundle - org.osgi.service.http;version=1.2.0 Bundle[id=16,gen=0].
javax.servlet.http;version=[2.5.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=[2.5.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].)
org.osgi.framework.BundleException: Bundle#20, unable to resolve: Missing package(s) or can not resolve all of the them:
org.osgi.service.http;version=[1.1.0,2.0.0) -- Could not resolve exporting bundle - org.osgi.service.http;version=1.2.0 Bundle[id=16,gen=0].
javax.servlet.http;version=[2.5.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=[2.5.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].
        at org.knopflerfish.framework.BundleImpl.getUpdatedState(BundleImpl.java:1259)
        at org.knopflerfish.framework.BundleImpl.finalizeActivation(BundleImpl.java:312)
        at org.knopflerfish.framework.PermissionOps.callFinalizeActivation(PermissionOps.java:265)
        at org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:295)
        at org.knopflerfish.bundle.frameworkcommands.FrameworkCommandGroup.cmdStart(FrameworkCommandGroup.java:1634)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at org.knopflerfish.service.console.CommandGroupAdapter.execute(CommandGroupAdapter.java:256)
        at org.knopflerfish.bundle.console.Command$2.run(Command.java:239)
        at java.security.AccessController.doPrivileged(AccessController.java:45)
        at org.knopflerfish.bundle.console.Command.run(Command.java:226)
        at java.lang.Thread.run(Thread.java:856)

另一个是我Pax Web将从 Knopflerfish 的教程中启动捆绑包。在这里,我尝试开始pax-web-jetty-bundle-1.0.2.jar (OPS4J Pax Web - Jetty Bundle)

[stderr] ## DEBUG: errors - FrameworkErrorEvent bundle #16
[stderr] ## DEBUG: errors - FrameworkErrorEvent throwable:
Couldn't start bundle: OPS4J Pax Web - Jetty Bundle (#16) (due to: org.osgi.framework.BundleException: Bundle#16, unable to resolve: Missing package(s) or can not resolve all of the them:
javax.security.sasl -- No providers found.
javax.management.remote -- No providers found.
javax.management.modelmbean -- No providers found.
javax.management -- No providers found.)
org.osgi.framework.BundleException: Bundle#16, unable to resolve: Missing package(s) or can not resolve all of the them:
javax.security.sasl -- No providers found.
javax.management.remote -- No providers found.
javax.management.modelmbean -- No providers found.
javax.management -- No providers found.
        at org.knopflerfish.framework.BundleImpl.getUpdatedState(BundleImpl.java:1259)
        at org.knopflerfish.framework.BundleImpl.finalizeActivation(BundleImpl.java:312)
        at org.knopflerfish.framework.PermissionOps.callFinalizeActivation(PermissionOps.java:265)
        at org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:295)
        at org.knopflerfish.bundle.frameworkcommands.FrameworkCommandGroup.cmdStart(FrameworkCommandGroup.java:1634)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at org.knopflerfish.service.console.CommandGroupAdapter.execute(CommandGroupAdapter.java:256)
        at org.knopflerfish.bundle.console.Command$2.run(Command.java:239)
        at java.security.AccessController.doPrivileged(AccessController.java:45)
        at org.knopflerfish.bundle.console.Command.run(Command.java:226)
        at java.lang.Thread.run(Thread.java:856)

最后,当我尝试运行pax-web-extender-war-0.8.0.jar (OPS4J Pax Web - Extender - War)此错误消息时,也会出现:

[stderr] ## DEBUG: errors - FrameworkErrorEvent bundle #17
[stderr] ## DEBUG: errors - FrameworkErrorEvent throwable:
Couldn't start bundle: OPS4J Pax Web - Extender - WAR (#17) (due to: org.osgi.framework.BundleException: Bundle#17, unable to resolve: Missing package(s) or can not resolve all of the them:
org.osgi.service.http;version=[1.0.0,2.0.0) -- Could not resolve exporting bundle - org.osgi.service.http;version=1.2.0 Bundle[id=16,gen=0].
javax.servlet.http;version=2.1.0 -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=2.1.0 -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].)
org.osgi.framework.BundleException: Bundle#17, unable to resolve: Missing package(s) or can not resolve all of the them:
org.osgi.service.http;version=[1.0.0,2.0.0) -- Could not resolve exporting bundle - org.osgi.service.http;version=1.2.0 Bundle[id=16,gen=0].
javax.servlet.http;version=2.1.0 -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=2.1.0 -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].
        at org.knopflerfish.framework.BundleImpl.getUpdatedState(BundleImpl.java:1259)
        at org.knopflerfish.framework.BundleImpl.finalizeActivation(BundleImpl.java:312)
        at org.knopflerfish.framework.PermissionOps.callFinalizeActivation(PermissionOps.java:265)
        at org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:295)
        at org.knopflerfish.bundle.frameworkcommands.FrameworkCommandGroup.cmdStart(FrameworkCommandGroup.java:1634)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at org.knopflerfish.service.console.CommandGroupAdapter.execute(CommandGroupAdapter.java:256)
        at org.knopflerfish.bundle.console.Command$2.run(Command.java:239)
        at java.security.AccessController.doPrivileged(AccessController.java:45)
        at org.knopflerfish.bundle.console.Command.run(Command.java:226)
        at java.lang.Thread.run(Thread.java:856)

我也尝试启动pax-web-jsp-1.0.2.jar (OPS4J Pax Web - Jsp Support)显示此错误消息:

[stderr] ## DEBUG: errors - FrameworkErrorEvent bundle #15
[stderr] ## DEBUG: errors - FrameworkErrorEvent throwable:
Couldn't start bundle: OPS4J Pax Web - Jsp Support (#15) (due to: org.osgi.framework.BundleException: Bundle#15, unable to resolve: Missing package(s) or can not resolve all of the them:
javax.tools -- No providers found.
javax.servlet.resources;version=[2.3.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.resources;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet.http;version=[2.3.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=[2.3.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].
javax.lang.model.util -- No providers found.
javax.lang.model.type -- No providers found.
javax.lang.model.element -- No providers found.
javax.lang.model -- No providers found.
javax.annotation.processing -- No providers found.)
org.osgi.framework.BundleException: Bundle#15, unable to resolve: Missing package(s) or can not resolve all of the them:
javax.tools -- No providers found.
javax.servlet.resources;version=[2.3.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.resources;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet.http;version=[2.3.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=[2.3.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].
javax.lang.model.util -- No providers found.
javax.lang.model.type -- No providers found.
javax.lang.model.element -- No providers found.
javax.lang.model -- No providers found.
javax.annotation.processing -- No providers found.
        at org.knopflerfish.framework.BundleImpl.getUpdatedState(BundleImpl.java:1259)
        at org.knopflerfish.framework.BundleImpl.finalizeActivation(BundleImpl.java:312)
        at org.knopflerfish.framework.PermissionOps.callFinalizeActivation(PermissionOps.java:265)
        at org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:295)
        at org.knopflerfish.bundle.frameworkcommands.FrameworkCommandGroup.cmdStart(FrameworkCommandGroup.java:1634)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at org.knopflerfish.service.console.CommandGroupAdapter.execute(CommandGroupAdapter.java:256)
        at org.knopflerfish.bundle.console.Command$2.run(Command.java:239)
        at java.security.AccessController.doPrivileged(AccessController.java:45)
        at org.knopflerfish.bundle.console.Command.run(Command.java:226)
        at java.lang.Thread.run(Thread.java:856)

根据我从错误消息中了解到的情况,捆绑包正在寻找这些包。有什么办法可以解决这个问题,并能够使用 OSGi 框架在 Android 上成功运行 Java Web 应用程序?

org.osgi.service.http;version=[1.1.0,2.0.0) -- Could not resolve exporting bundle - org.osgi.service.http;version=1.2.0 Bundle[id=16,gen=0].
javax.servlet.http;version=[2.5.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet.http;version=2.5.0 Bundle[id=16,gen=0].
javax.servlet;version=[2.5.0,3.0.0) -- Could not resolve exporting bundle - javax.servlet;version=2.5.0 Bundle[id=16,gen=0].

javax.security.sasl -- No providers found.
javax.management.remote -- No providers found.
javax.management.modelmbean -- No providers found.
javax.management -- No providers found.
4

1 回答 1

1

首先,我强烈建议对所有 Pax-Web 包使用相同的版本,其次您缺少一个 servlet API 包。此外,您似乎还缺少其他几个 Pax-Web 捆绑包。您很可能需要以下捆绑包:

  • pax-web-api
  • pax-web-jetty-bundle
  • pax-web-jsp
  • pax-web-运行时
  • pax-web-spi

如果你想使用战争,你需要

  • pax-web-extender-war
  • pax-url-战争
  • 还有几个...

Pax-Web 的最新版本是 3.0.2,因此您应该根据您要执行的操作谨慎选择。您可能会发现检查 Pax-Web 的 ITests(取决于您要使用的版本)以获取有关需要哪些捆绑包的灵感很有帮助。我建议从最小设置开始。这样,您首先从 http-service 开始,然后根据您的需求对其进行增强。

查看 Github 上的Pax-Web 项目,尤其是示例和测试模块,了解更多详细信息。

于 2013-11-05T08:05:16.553 回答