我正在编写一个名为ZAP的 Java 应用程序的扩展。扩展是一个内嵌Equinox bundle ( )的 fat/uber jar 。此 jar 中还包含其他捆绑包,位于子目录中。如如何嵌入 OSGi中所述,OSGi 框架正在启动。org.eclipse.osgi
bundles
我正在尝试按照Eclipse 的“Console Shell”文档中概述的步骤让 Felix GoGo shell 工作。它指定了以下必需的捆绑包:
org.apache.felix.gogo.command
org.apache.felix.gogo.runtime
org.apache.felix.gogo.shell
org.eclipse.equinox.console
除了春分 / org.eclipse.osgi
。由于 Equinox 不在类路径上,因此我将org.osgi.framework.system.packages.extra
配置设置为 Equinox 包指定的值,在此处Export-Package
可见。
一旦框架处于 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:也许是红鲱鱼
在随机故障排除中,我想执行此处概述的最终阴影 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)
执行阴影罐,不是那么多:
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 围绕问题工作
我通过其目录将 Equinox 捆绑包添加到 ZAP 的类路径中lib
,并将其从内联到扩展 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 可以提供帮助?