如何克服 OSGi 中的“缺少可选导入的包”问题
我使用“maven-bundle-plugin”编写了一个OSGi包(我尝试将“jruby-complete-1.4.0.jar”制作为osgi包,请注意,唯一的依赖项是“jruby-complete-1.4.0.jar” ")..当我使用 diag 命令(#diag XX)通过 osgi 控制台检查捆绑包时,它说缺少一些包;
osgi> diag 51
reference:file:dropins/jruby-complete-1.4.0.wso2v1.jar [51]
Direct constraints which are unresolved:
Missing optionally imported package com.sun.mirror.apt_0.0.0.
Missing optionally imported package com.sun.mirror.declaration_0.0.0.
Missing optionally imported package com.sun.mirror.type_0.0.0.
Missing optionally imported package com.sun.mirror.util_0.0.0.
Missing optionally imported package org.apache.bsf.util_0.0.0.
Missing optionally imported package org.jgrapht_0.0.0.
Missing optionally imported package org.jgrapht.graph_0.0.0.
Missing optionally imported package sun.misc_0.0.0.
我的 pom 是这样的;
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>
com.kenai.*,
com.sun.jna.*,
org.jruby.*,
org.joni.*,
</Export-Package>
<Import-Package>
*;resolution:=optional
</Import-Package>
<Fragment-Host>bsf-all</Fragment-Host>
<DynamicImport-Package>*</DynamicImport-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=true;</Embed-Dependency>
</instructions>
</configuration>
</plugin>
因此,我尝试在 pom[2] 中的
选项中添加那些“可选缺少的包” 但它带来了更多问题,例如;
ference:file:dropins/jruby-complete-1.4.0.wso2v1.jar [51]
Constraints from the fragment conflict with the host: Import-Package: *; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.apt; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.declaration; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.type; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.util; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.management; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.script; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.swing.plaf.basic; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.apache.bsf; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.apache.bsf.util; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jgrapht; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jgrapht.graph; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.anno; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.exceptions; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.runtime; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.runtime.builtin; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: sun.misc; version="0.0.0"
Direct constraints which are unresolved:
Missing imported package com.sun.mirror.apt_0.0.0.
Missing imported package com.sun.mirror.declaration_0.0.0.
Missing imported package com.sun.mirror.type_0.0.0.
Missing imported package com.sun.mirror.util_0.0.0.
Missing imported package org.apache.bsf.util_0.0.0.
Missing imported package org.jgrapht_0.0.0.
Missing imported package org.jgrapht.graph_0.0.0.
Missing optionally imported package org.jruby.anno_[1.4.0,2.0.0).
Missing optionally imported package org.jruby.exceptions_[1.4.0,2.0.0).
Missing optionally imported package org.jruby.runtime_[1.4.0,2.0.0).
Missing optionally imported package org.jruby.runtime.builtin_[1.4.0,2.0.0).
Missing imported package sun.misc_0.0.0.
pom.xml [2];
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>
com.kenai.*,
com.sun.jna.*,
org.jruby.*,
org.joni.*,
</Export-Package>
<Import-Package>
com.sun.mirror.apt.*,
com.sun.mirror.declaration.*,
com.sun.mirror.type.*,
com.sun.mirror.util.*,
org.apache.bsf.util.*,
org.jgrapht.*,
org.jgrapht.graph.*,
sun.misc.*,
*;resolution:=optional
</Import-Package>
<Fragment-Host>bsf-all</Fragment-Host>
<DynamicImport-Package>*</DynamicImport-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=true;</Embed-Dependency>
</instructions>
</configuration>
</plugin>
我怎样才能克服上述问题? 我正在导出一些包,我需要其他包......我在这里做错了什么吗?
I wrote an OSGi bundle using "maven-bundle-plugin"(where i try to make the "jruby-complete-1.4.0.jar" as osgi bundle, note that only dependency is "jruby-complete-1.4.0.jar")..When i check the bundle via osgi console using diag command( #diag XX) it says some packages are missing;
osgi> diag 51
reference:file:dropins/jruby-complete-1.4.0.wso2v1.jar [51]
Direct constraints which are unresolved:
Missing optionally imported package com.sun.mirror.apt_0.0.0.
Missing optionally imported package com.sun.mirror.declaration_0.0.0.
Missing optionally imported package com.sun.mirror.type_0.0.0.
Missing optionally imported package com.sun.mirror.util_0.0.0.
Missing optionally imported package org.apache.bsf.util_0.0.0.
Missing optionally imported package org.jgrapht_0.0.0.
Missing optionally imported package org.jgrapht.graph_0.0.0.
Missing optionally imported package sun.misc_0.0.0.
My pom is like;
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>
com.kenai.*,
com.sun.jna.*,
org.jruby.*,
org.joni.*,
</Export-Package>
<Import-Package>
*;resolution:=optional
</Import-Package>
<Fragment-Host>bsf-all</Fragment-Host>
<DynamicImport-Package>*</DynamicImport-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=true;</Embed-Dependency>
</instructions>
</configuration>
</plugin>
So, i tried add those "optional missing packages" in <Import-Package>
option as in pom[2]
But it gives more issues like;
ference:file:dropins/jruby-complete-1.4.0.wso2v1.jar [51]
Constraints from the fragment conflict with the host: Import-Package: *; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.apt; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.declaration; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.type; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.util; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.management; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.script; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.swing.plaf.basic; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.apache.bsf; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.apache.bsf.util; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jgrapht; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jgrapht.graph; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.anno; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.exceptions; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.runtime; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.runtime.builtin; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: sun.misc; version="0.0.0"
Direct constraints which are unresolved:
Missing imported package com.sun.mirror.apt_0.0.0.
Missing imported package com.sun.mirror.declaration_0.0.0.
Missing imported package com.sun.mirror.type_0.0.0.
Missing imported package com.sun.mirror.util_0.0.0.
Missing imported package org.apache.bsf.util_0.0.0.
Missing imported package org.jgrapht_0.0.0.
Missing imported package org.jgrapht.graph_0.0.0.
Missing optionally imported package org.jruby.anno_[1.4.0,2.0.0).
Missing optionally imported package org.jruby.exceptions_[1.4.0,2.0.0).
Missing optionally imported package org.jruby.runtime_[1.4.0,2.0.0).
Missing optionally imported package org.jruby.runtime.builtin_[1.4.0,2.0.0).
Missing imported package sun.misc_0.0.0.
pom.xml [2];
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>
com.kenai.*,
com.sun.jna.*,
org.jruby.*,
org.joni.*,
</Export-Package>
<Import-Package>
com.sun.mirror.apt.*,
com.sun.mirror.declaration.*,
com.sun.mirror.type.*,
com.sun.mirror.util.*,
org.apache.bsf.util.*,
org.jgrapht.*,
org.jgrapht.graph.*,
sun.misc.*,
*;resolution:=optional
</Import-Package>
<Fragment-Host>bsf-all</Fragment-Host>
<DynamicImport-Package>*</DynamicImport-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=true;</Embed-Dependency>
</instructions>
</configuration>
</plugin>
How can i overcome above issue?
I'm exporting some packages which, i need for other bundles...Am i doing anything wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些包是可选导入的,所以这里不一定有任何问题。
发布者修改问题后更新:
捆绑包插件通过检查捆绑包中的字节码发现了这些依赖项。它们通常是强制性依赖项,但由于某种原因,您通过添加
*;resolution:=optional
将它们设为可选。不知道为什么你这样做,但没关系......解析包的正确方法是找到导出它们的包。例如,您的包需要
org.jgrapht
包。因此,您需要安装导出该包的捆绑包。唯一的例外是
sun.misc
包,它显然来自 JRE,但不应该在一般情况下使用。 OSGi 框架默认情况下不提供此包,但您可以通过添加以下设置来配置它们:放置此设置的确切文件或位置取决于您的 OSGi 框架 - 您尚未指定正在使用哪一个,因此无论是什么,请检查其文档以了解如何传递配置设置。
Those packages are optional imports, so there isn't necessarily any problem here.
UPDATE after poster amended question:
These dependencies have been discovered by the bundle plugin by inspecting the bytecode in your bundle. They would normally be mandatory dependencies but for some reason you have made them optional by adding
<Import-Package>*;resolution:=optional</Import-Package>
. Not sure why you did that but never mind...The proper way to resolve packages is to find a bundle that exports them. For example, your bundle needs the package
org.jgrapht
. Therefore you need to install the bundle that exports that package.The one exception is the
sun.misc
package, which obviously comes from the JRE but is not supposed to be used in general. OSGi framework do not make this package available by default, but you can configure them by adding the following setting:The exact file or location to place this setting depends on your OSGi framework -- you haven't specified which one you are using, so whatever it is please check its documentation on how to pass configuration settings.