包使用冲突:捆绑包启动时导入包 [英] Package uses conflict: Import-Package on startup of a bundle
问题描述
尝试安装htmlunit捆绑包时出现以下错误:
I am getting the following error when trying to install the htmlunit bundle:
com.springsource.com.gargoylesoftware.htmlunit_2.6.0 [370] could not be resolved.
Reason: Package uses conflict:
Import-Package: org.apache.commons.logging.impl; version="1.1.1"
我在这是我的发现:
捆绑包com.springsource.com.gargoylesoftware.htmlunit_2.6.0
具有以下说明:
And here are my findings:
The bundle com.springsource.com.gargoylesoftware.htmlunit_2.6.0
has the following instructions:
Import-Package: \
org.apache.commons.logging;version="[1.1.1, 2.0.0)",\
org.apache.commons.logging.impl;version="[1.1.1, 2.0.0)"
在我的OSGi中唯一具有此使用约束的捆绑软件是com.springsource.org.apache.commons.logging
,其具有以下说明:
The only bundle that has this in its use constraint in my OSGi is com.springsource.org.apache.commons.logging
, which has these instructions:
Export-Package: \
org.apache.commons.logging;version="1.1.1",\
org.apache.commons.logging.impl;version="1.1.1";\
uses:="javax.servlet,
org.apache.avalon.framework.logger,
org.apache.commons.logging,
org.apache.log,
org.apache.log4j"
Import-Package: \
javax.servlet;version="[2.1.0, 3.0.0)";resolution:=optional,\
org.apache.avalon.framework.logger;version="[4.1.3, 4.1.3]";resolution:=optional,\
org.apache.log;version="[1.0.1, 1.0.1]";resolution:=optional,\
org.apache.log4j;version="[1.2.15, 2.0.0)";resolution:=optional
在这一点上,我很困惑,因为我无法弄清楚问题是什么以及如何解决它,尽管从上面提供的内容来看应该很清楚,但对我而言不是:(
At this point I am stuck as I can't figure out what the problem is and how to resolve it although from what I provided above it should be clear, but not to me :(
有什么想法吗??
推荐答案
这很可能与"import-what-you-export"有关.
This most likely has to do with 'import-what-you-export'.
uses
约束指出如果要导入此程序包,请确保使用与我相同的程序包",这不仅表示程序包的版本,而且还表示相同包,由同一包导出.
您的第二个捆绑软件导出了logging
和logging.impl
包,并声明如果您要使用logging.impl
,请使用与我相同的logging
",并且它也恰好导出了一个.这意味着任何想要导入logging.impl
的人也必须从您的捆绑软件中导入logging
,因为它无法连接到任何其他logging
软件包.
如果框架中存在另一个logging
副本,这可能会导致问题,该副本可能会更早解决.
A uses
constraint states "if you want to import this package, better make sure you're using the same packages that I am", which not only means the version of the package, but the identical package, exported by the same bundle.
Your second bundle exports the logging
and logging.impl
package, stating that "if you want to use logging.impl
, use the same logging
that I do", and it also happens to export one. This means that anyone who wants to import logging.impl
must also import logging
from your bundle, since it cannot be wired to any other logging
package.
This leads to problems if there is another copy of logging
around in the framework, which may get resolved earlier.
解决这个问题的最简单方法可能是将logging
添加到第二个捆绑软件的Import-Package
中.这样一来,您就可以完全选择要在框架中使用哪个程序包.
Probably the easiest way to solve this is to add logging
to the Import-Package
of your second bundle. This way, you leave the choice of exactly which package to use up to the framework.
无关紧要的是,除去所有这些";resolution:=optional
语句,除非您的代码可以真正解决某些程序包不可用的情况.如果没有javax.servlet
可用,您的捆绑包就可以工作,我会感到非常惊讶.
On an unrelated note, get rid of all those ";resolution:=optional
statements, unless you're code can really work with the situation in which some package is not available. I would be highly surprised of your bundle can work without having javax.servlet
available.
这篇关于包使用冲突:捆绑包启动时导入包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!