【问题标题】:Felix GoGo Shell throws MalformedURLException: unknown protocol: bundleresource in EquinoxFelix GoGo Shell 抛出 MalformedURLException:未知协议:Equinox 中的 bundleresource
【发布时间】:2016-05-17 18:12:49
【问题描述】:

我正在将an extension 写入一个名为ZAP 的Java 应用程序。该扩展是一个胖/超级 jar,包含 Equinox 捆绑包 (org.eclipse.osgi) inlined。额外的 bundles 也包含在这个 jar 中,位于子目录 bundles 中。如How To Embed OSGi 所述,OSGi 框架正在启动。

我正在尝试让 Felix GoGo shell 工作,遵循 the steps outlined 通过 Eclipse 的“控制台外壳”文档。它指定了以下必需的捆绑包:

  • org.apache.felix.gogo.command
  • org.apache.felix.gogo.runtime
  • org.apache.felix.gogo.shell
  • org.eclipse.equinox.console

除了 Equinox / org.eclipse.osgi。由于 Equinox 不在类路径上,因此我将 org.osgi.framework.system.packages.extra 配置设置为 Equinox 捆绑包指定的 Export-Package 值,可见 here

一旦框架处于 ACTIVE 状态,我会在 Eclipse 中(或通过 Eclipse 外部的命令行)看到以下堆栈跟踪:

Starting OSGi framework...
OSGi framework state: 32
gogo: MalformedURLException: unknown protocol: bundleresource
java.net.MalformedURLException: unknown protocol: bundleresource
  at java.net.URL.<init>(URL.java:593)
  at java.net.URL.<init>(URL.java:483)
  at java.net.URL.<init>(URL.java:432)
  at java.net.URI.toURL(URI.java:1089)
  at org.apache.felix.gogo.shell.Shell.readScript(Shell.java:209)
  at org.apache.felix.gogo.shell.Shell.source(Shell.java:192)
  at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:109)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
  at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
  at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
  at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)
  at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
  at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
  at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
  at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
  at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
  at java.lang.Thread.run(Thread.java:745)

GoGo 似乎没有使用 Equinox URL 处理程序。我注意到与它们相关的以下软件包不在 Equinox 的 Export-Package 中:

  • org.eclipse.osgi.storage.url
  • org.eclipse.osgi.storage.url.bundleresource
  • org.eclipse.osgi.storage.url.bundleentry

所以我也将它们包含在org.osgi.framework.system.packages.extra 包列表中。这没有帮助。

安装和启动包没有任何明显的错误。

如何让 GoGo 使用 Equinox 的自定义 URL 处理程序?

更新 1:也许是红鲱鱼

在随机故障排除中,我想按照here 的概述执行最终的阴影 jar。我将原始 org.eclipse.osgi 包和阴影 jar 复制到同一目录中。有一个 configuration/config.ini 指定要加载的包。

执行 stock bundle 会打开控制台:

$ java -cp ~/.p2/pool/plugins/org.eclipse.osgi_3.11.0.v20160121-2005.jar org.eclipse.core.runtime.adaptor.EclipseStarter -console
osgi> ss
"Framework is launched."


id  State       Bundle
0 ACTIVE      org.eclipse.osgi_3.11.0.v20160121-2005
1 ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036
2 ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215
3 ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605
4 ACTIVE      org.eclipse.equinox.console_1.1.200.v20150929-1405
osgi> exit
Really want to stop Equinox? (y/n; default=y)

执行带阴影的 jar,没那么多:

java -cp semiotics-alpha-1.zap org.eclipse.core.runtime.adaptor.EclipseStarter -console
java.lang.NullPointerException: A null service reference is not allowed.
  at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:617)
  at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:299)
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:231)
  at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:208)

这可能是一个完全的红鲱鱼......我对 OSGi 非常无知,这是我第一次亲身体验它。但是,我希望阴影 jar 的执行与股票 Equinox jar 没有什么不同。因为我不明白为什么会有不同,所以我会在那里挖掘,因为没有更好的地方可以挖掘......

更新 2:Classpath 上的 Equinox 解决问题

我通过 lib 目录将 Equinox 捆绑包添加到 ZAP 的类路径中,并将其从内联到扩展 jar 中删除。这样做并调整 ServiceLoader.load 调用以不包含类加载器(默认为系统类加载器)有效:

Starting bundle: org.apache.felix.gogo.shell_0.10.0.v201212101605 [1]
Starting bundle: org.eclipse.equinox.console_1.1.100.v20141023-1406 [2]
Starting bundle: org.apache.felix.gogo.command_0.10.0.v201209301215 [3]
Starting bundle: org.eclipse.emf.ecore_2.11.2.v20160208-0816 [4]
Starting bundle: org.eclipse.emf.common_2.11.1.v20160208-0816 [5]
Starting bundle: org.apache.felix.gogo.runtime_0.10.0.v201209301036 [6]
osgi> ss
"Framework is launched."


id  State       Bundle
0 ACTIVE      org.eclipse.osgi_3.11.0.v20160121-2005
1 ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605
2 ACTIVE      org.eclipse.equinox.console_1.1.100.v20141023-1406
3 ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215
4 ACTIVE      org.eclipse.emf.ecore_2.11.2.v20160208-0816
5 ACTIVE      org.eclipse.emf.common_2.11.1.v20160208-0816
6 ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036
osgi> 

根本问题可能是 jar 的内联方式,可能与 MANIFEST.MF 文件有关。可能相关,我现在不需要为 org.osgi.framework.system.packages.extra 提供值。

我将不回答这个问题,因为最初的目的是将 OSGi 库作为阴影工件包含在内。也许 bndtools 可以提供帮助?

【问题讨论】:

    标签: osgi equinox gogo-shell embedded-osgi


    【解决方案1】:

    好吧,似乎缺少描述性的META-INF/MANIFEST.MF 是罪魁祸首:

    • 删除 (jar uM...) 然后更新 (jar um...) 阴影 jar 的 MANIFEST.MF 以作为 Equinox 清单的副本,将 Bundle-Version 编号修改为以 1766 结尾而不是 1700
    • 从 ZAP 的类路径中删除了 Equinox

    然后我按原样加载了扩展程序。 GoGo shell 启动:

    osgi> 13177 [AWT-EventQueue-0] INFO org.parosproxy.paros.control.Control  - New Session
    ss
    "Framework is launched."
    
    
    id  State       Bundle
    0 ACTIVE      org.eclipse.osgi_3.10.102.v20160118-1766
    1 ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036
    2 ACTIVE      org.eclipse.emf.common_2.11.1.v20160208-0816
    3 ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605
    4 ACTIVE      org.eclipse.equinox.console_1.1.100.v20141023-1406
    5 ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215
    6 ACTIVE      org.eclipse.emf.ecore_2.11.2.v20160208-0816
    osgi> 
    

    我看到系统捆绑包以相同的修改版本号结尾,因此它尊重添加的MANIFEST.MF。所以根本问题是不完整的系统捆绑清单。复制现有的(Equinox's)效果很好。它也适用于直接的命令行测试:

    $ java -cp semiotics-alpha-1.zap org.eclipse.core.runtime.adaptor.EclipseStarter -console
    osgi> exit
    Really want to stop Equinox? (y/n; default=y)  y
    

    不知道我是否会使用这种方法。至少我知道我需要做什么如果我想使用这种方法。

    【讨论】:

      猜你喜欢
      • 2018-12-05
      • 2017-03-29
      • 2019-03-26
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多