使用约束违反。无法解析资源 -javax.xml.bind.annotation 和 jakarta.xml.bind-api

Tia*_*ado 5 java osgi apache-karaf

我搜索了 looooot,但找不到解决我的问题的方法。

我使用 osgi、karaf 和 java 8。

我有一些模块,例如:

WEBSERVICE-这个模块里面的东西可以说API,持久性,适配器

持久性和 api 启动正常,但适配器给出了该错误:

Uses constraint violation. Unable to resolve resource adapter [adapter [288](R 288.2)] 
because it is exposed to package 'javax.xml.bind.annotation' from resources 
org.apache.felix.framework [org.apache.felix.framework [0](R 0)] and 
jakarta.xml.bind-api [jakarta.xml.bind-api [79](R 79.0)] via two dependency 
chains.
Run Code Online (Sandbox Code Playgroud)

链在适配器和 api 中。

但是,这是什么意思?

我可以将它安装为功能,它们都会启动,但我的另一包将放在 GracePeriod 中,如果我在 karaf 上执行 DIAG,它会说:

Status: GracePeriod
Declarative Services
Blueprint
01/09/19 19:00
Missing dependencies:
(&(osgi.unit.name=example_db)(objectClass=javax.persistence.EntityManager))
Run Code Online (Sandbox Code Playgroud)

请注意,我有其他 webservice 模块,其中一些工作正常,我检查了 pom,它们具有相同的依赖项和相同的版本

数据源也很好,我已经尝试添加一些功能,如 hibernate.entityManager,但它不起作用。

Mil*_*kov 7

根据您提供的有限信息,您很可能在运行时有不同包导出的同一包的两个版本。

这本身不是问题,但是,正如在这个答案中所解释的那样,它会导致错误

  • 捆绑包A需要来自的B包和来自的包C
  • 捆绑包B需要来自相同软件包的不同版本C

In your particular case the package in question seems to be javax.xml.bind.annotation which appears to be exported in 2 different versions by org.apache.felix.framework bundle and jakarta.xml.bind-api bundle.

It's hard to say what is the best way way to fix that without knowing what are the exact requirements and capabilities of the bundles you are trying to install.

UPDATE:

Here are some things you can use to debug the situation:

  • Calling package:exports | grep javax.xml.bind.annotation will tell you which bundles export the package at what versions
  • Calling package:imports | grep javax.xml.bind.annotation will tell you which bundles imports the package at what versions
  • Calling bundle:diag <YOUR_BUNDLE_ID> will give you detailed information why the bundle was not resolved