问题描述
我在Bundle-Classpath上放了一些罐子.下面的行显示了我的pom.xml中的条目,该条目使用Felix插件为捆绑包创建manigest.mf.
I have put a few jars on my Bundle-Classpath. The line below shows the entry in my pom.xml, which uses the Felix plugin to create the manigest.mf for the bundle.
<Bundle-ClassPath>.,lib/com.springsource.org.h2-1.0.71.jar,lib/com.springsource.org.apache.lucene-2.3.2.jar,lib/com.springsource.org.apache.lucene.search-2.3.2.jar</Bundle-ClassPath>
这些罐子都有导入包的类,但是从我的看到,它们都具有MANIFEST.MF,它具有自己的(准确的)Import-Package语句列表.
These jars have classes which import packages, but from what I can see, they all have a MANIFEST.MF, which has it's own (accurate) list of Import-Package statements.
但是,当我构建项目(使用Maven和bundle插件)时,它报告一个错误,因为它无法解析对某些类的引用.具体错误是:
However, when I build my project (using Maven and the bundle plugin), it reports an error because it cannot resolve references to certain classes. Specifically the error is:
Unresolved references to [com.sun.tools.javac, javax.naming, javax.naming.spi, javax.servlet, javax.servlet.http, javax.sql, javax.transaction.xa]
所有这些错误都来自com.springsource.org.h2-1.0.71.jar,所有这些软件包都导入了该jar的清单中.
All of these errors come from com.springsource.org.h2-1.0.71.jar and all these packages are imported in the manifest of that jar.
我无法理解:
- 如果这些软件包已经导入com.springsource.org.h2-1.0.71.jar的MANIFEST> MF中,为什么会抱怨Maven软件包插件
- 为什么问题仅来自com.springsource.org.h2-1.0.71.jar?我尝试删除了特定的jar,尽管com.springsource.org.apache.lucene.search-2.3.2.jar在MANIFEST.MF中也有几个Import-Package条目,但构建过程还是很顺利的.
关于第二点,我做了一些调查,我觉得这是有规律的. com.springsource.org.apache.lucene.search-2.3.2.jar在清单中指定的所有导入都由com.springsource.org.apache.lucene-2.3.2.jar满足,该文件也已指定在Bundle-Classpath上.
About the second point, I did some investigation, and I feel like there is a pattern. All the imports which com.springsource.org.apache.lucene.search-2.3.2.jar specifies in it's manifest, are being satisfied by com.springsource.org.apache.lucene-2.3.2.jar, which is also specified on the Bundle-Classpath.
com.springsource.org.apache.lucene-2.3.2.jar(在Bundle-Classpath上)满足了com.springsource.org.h2-1.0.71.jar的依赖关系.错误消息中未列出,但是,错误消息中列出了Bundle-Classpath上的jar不满足的那些依赖项.
The dependencies of com.springsource.org.h2-1.0.71.jar which are being satisfied by com.springsource.org.apache.lucene-2.3.2.jar (which is on the Bundle-Classpath), are not listed in the error message, however, those dependencies which are not satisfied by jars on the Bundle-Classpath are being listed in the error message.
不太确定发生了什么.关于Bundle-Classpath中指定的jar文件的规则是什么?是否必须将其清单的进口(即使在Import-Package中指定了进口)元素也必须列在主项目的pom中?还是Maven捆绑插件正在执行的操作?如果是后者,是否有办法摆脱执行?
Not quite sure what is happening. What is the rule regarding jar files which are specified on the Bundle-Classpath ? Do their imports (even when they are specified in the Import-Package) element of their manifest, have to be listed in the main project's pom ? Or is this something which the Maven bundle plugin is enforcing ? If the latter is the case, is there a way to get away from the enforcing ?
推荐答案
当您通过Embed-Dependency标签嵌入任何jar时,maven-bundle-plugin还将分析该jar并将引用的软件包添加到主机捆绑包Import-包裹清单.通常,根据使用的功能,此类软件包是可选的.例如,在您的用例中,H2 jar依赖于Lucene(某些功能的Servlet API).如果您的使用场景不需要这些功能,则可以将这些程序包标记为可选
When you embed any jar via Embed-Dependency tag then the maven-bundle-plugin would analyze that jar also and add the referred packages to the host bundle Import-Package list. Mostly such packages are optional depending on the feature used. For example in your usecase the H2 jar has dependency on Lucene, Servlet API for certain features. if your usage scenario does not require these features then you can mark these packages as optional
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<obrRepository>NONE</obrRepository>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
..
<Embed-Dependency>
h2
</Embed-Dependency>
<Import-Package>
org.osgi.service.jdbc.*;
org.apache.lucene.*;
javax.transaction.*;resolution:=optional,
*
</Import-Package>
</instructions>
</configuration>
</plugin>
在上面的配置中,我们将此类软件包标记为可选.主要问题是根据您的使用情况确定包装清单
In above config we mark such packages as optional. The main problem is to determine the package list depending on your usage
一种快速而肮脏的方法是将所有标记为可选导入. 应作为最后的手段 .由于某些有效的导入将被标记为可选,而OSGi fwk将无法对其进行检查.
One quick and dirty way is to mark all as optional imports. Should be used as a last resort. As some valid imports would be marked optional and OSGi fwk would not be able to check them.
<Import-Package>
*;resolution:=optional
</Import-Package>
还请注意,H2 jar是有效的OSGi捆绑包,因此您可以直接部署它.
Also note that H2 jar is a valid OSGi bundle so you can deploy it directly.
这篇关于如何处理来自Bundle-Classpath上的jar的Import-Package条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!