gpt4 book ai didi

java - OSGi `uses` 约束违规,即使存在兼容的导出器

转载 作者:行者123 更新时间:2023-12-02 09:53:21 25 4
gpt4 key购买 nike

当我尝试在 OSGi 容器中安装 bundle 时,我看到此错误:

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 加载类最终只会在包com.example.resource1(它导出仅有效版本的包)。因此,在 bundle 的某种“连接”状态下(它在运行时传递地导入的每个已解析的包),永远不应该存在不同版本的包。

这称为类空间一致性,在 OSGi Core 7 - 3.7.6 Package Constraints 中定义。 .

一旦核心 JVM 学会区分不同版本中的类,可能就不再需要这种限制 - 只要结果明确,就可以对其进行控制。

关于java - OSGi `uses` 约束违规,即使存在兼容的导出器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56155991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com