我正在将an extension写入名为ZAP的Java应用程序。扩展名是胖/超级jar,具有Equinox包(org.eclipse.osgi
)inlined。此jar中还包含其他bundles,位于子目录bundles
内。正如How To Embed OSGi中所述,正在启动OSGi框架。
我试图让Felix GoGo shell在the steps outlined之后通过Eclipse" Console Shell"文档。它指定了以下必需的包:
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&#39; 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处理程序?
在随机问题排查中,我想按照here概述执行最终的阴影jar。我将原始org.eclipse.osgi
包和阴影jar复制到同一目录中。有configuration/config.ini
指定要加载的包。
执行股票捆绑包会打开控制台:
$ 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非常无知,这是我第一次亲身体验它。但是,我希望阴影罐的执行与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可以提供帮助吗?
答案 0 :(得分:0)
好吧,似乎缺乏描述性的META-INF/MANIFEST.MF
是罪魁祸首:
jar uM...
),然后更新(jar um...
)带阴影的jar MANIFEST.MF
成为Equinox清单的副本,修改{{1} }号码以Bundle-Version
与1766
结尾。然后我按原样加载了扩展名。 GoGo shell启动:
1700
我看到系统包以相同的修改版本号结尾,因此它尊重添加的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>
。因此,潜在的问题是不完整的系统捆绑清单。复制现有的(Equinox&#39; s)效果很好。它也适用于直接命令行测试:
MANIFEST.MF
如果我不使用这种方法,请不要使用Dunno。至少我知道我需要做什么如果我想使用这种方法。