Java OSGi`使用`约束冲突,即使存在兼容的导出器

Java OSGi`使用`约束冲突,即使存在兼容的导出器,java,osgi,apache-karaf,apache-felix,osgi-bundle,Java,Osgi,Apache Karaf,Apache Felix,Osgi Bundle,当我尝试在我的OSGi容器中安装捆绑包时,我看到了这个错误: Error executing command: Uses constraint violation. Unable to resolve resource com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT] because it is exposed to package 'javax.jms' from resources com.example.resourc

当我尝试在我的OSGi容器中安装捆绑包时,我看到了这个错误:

Error executing command: Uses constraint violation. Unable to resolve resource com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT] because it is exposed to package 'javax.jms' from resources com.example.resource1 [com.example.resource1/2.0.1] and com.example.resource2 [com.example.resource2/1.1.1] via two dependency chains.

Chain 1:
  com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT]
    import: (&(osgi.wiring.package=javax.jms)(version>=2.0.0)(!(version>=3.0.0)))
     |
    export: osgi.wiring.package: javax.jms
  com.example.resource1 [com.example.resource1/2.0.1]

Chain 2:
  com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT]
    import: (&(osgi.wiring.package=com.example.intermediary)(version>=7.2.0)(!(version>=8.0.0)))
     |
    export: osgi.wiring.package=com.example.intermediary; uses:=javax.jms
  com.example.intermediary [com.example.intermediary/7.2.0]
    import: (&(osgi.wiring.package=javax.jms)(version>=1.1.0)(!(version>=3.0.0)))
     |
    export: osgi.wiring.package: javax.jms
  com.example.resource2 [com.example.resource2/1.1.1]

据我所知,com.example.resource1导出的包版本可以满足这两个链。那么为什么它不在这两个地方都使用resource1呢?

这是行不通的,因为不能保证从
javax.jms
加载类只会在bundle
com.example.resource1
(它导出包的唯一有效版本)。因此,在捆绑包的特定“连接”状态中(它在运行时以传递方式导入的每个解析包),不应该有不同版本的包

这称为类空间一致性,在中定义


一旦核心JVM学会了区分不同版本中的类,就可能不再需要这种限制了——只要结果清楚,有人可以控制它。

是的,但我想说的是,考虑到这里存在的捆绑包,有可能保持类空间的一致性,完全不使用com.example.resource2。较高版本的导出器可以满足这两个依赖关系链而不发生冲突。那么为什么容器不这样做呢?这可能是部署时的时间问题。如果在解析
com.example.resource1
com.example.resource2
时,
com.example.resource2
都可用于解析程序,则它将连接到更高版本,除非存在另一个版本约束,不允许使用更高的主版本。如果对
com.example.intermediate
进行捆绑包刷新无法解决此问题,则两个捆绑包中都有其他需要以不同方式解决的需求。我希望您没有自己打包并导出
javax.jms