maven之如何克服 OSGi 中的 "Missing optionally imported package"问题
我使用“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>
因此,我尝试在 <Import-Package>
中添加那些“可选的缺失包” 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>
我怎样才能克服上述问题? 我正在导出一些包,我需要其他包...我在这里做错了什么吗?
请您参考如下方法:
这些包是可选导入的,所以这里不一定有任何问题。
更新 发布者修改问题后:
bundle 插件通过检查您的 bundle 中的字节码发现了这些依赖关系。它们通常是强制依赖项,但出于某种原因,您通过添加 <Import-Package>*;resolution:=optional</Import-Package>
将它们设为可选。 .不确定你为什么那样做,但没关系......
解析包的正确方法是找到一个导出它们的包。例如,您的包需要包 org.jgrapht
.因此,您需要安装导出该包的包。
唯一的异常(exception)是 sun.misc
包,它显然来自 JRE,但通常不应该使用。 OSGi 框架默认不提供此包,但您可以通过添加以下设置来配置它们:
org.osgi.framework.system.packages.extra=sun.misc
放置此设置的确切文件或位置取决于您的 OSGi 框架——您尚未指定您使用的是哪个框架,因此无论它是什么,请查看其文档以了解如何传递配置设置。
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。