我使用“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] 中的
<Import-Package>
选项中添加那些“可选的丢失包”但它提供了更多的问题,例如;
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 框架——您尚未指定使用的是哪个框架,因此无论是什么,请查看其有关如何传递配置设置的文档。
关于maven - 如何克服 OSGi 中的 "Missing optionally imported package"问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8727054/