OSGi:javax.annotation冲突:Java SE与Java EE [英] OSGi: javax.annotation conflict: Java SE vs Java EE

查看:423
本文介绍了OSGi:javax.annotation冲突:Java SE与Java EE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java SE OSGi(Apache Felix)环境中,我正在尝试使用PAX CDI和Weld 2.2.6.Final集成CDI。

In a Java SE OSGi (Apache Felix) environment, I'm trying to integrate CDI using PAX CDI and Weld 2.2.6.Final.

我是目前收到以下错误:

I'm currently getting the following error:

ERROR: Bundle org.jboss.weld.osgi-bundle [45] Error starting file:///someDir/org/jboss/weld/weld-osgi-bundle/2.2.6.Final/weld-osgi-bundle-2.2.6.Final.jar (org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision org.jboss.weld.osgi-bundle [45.0] because it is exposed to package 'javax.annotation' from bundle revisions org.jboss.spec.javax.annotation.jboss-annotations-api_1.2_spec [39.0] and org.apache.felix.framework [0] via two dependency chains.

Chain 1:
  org.jboss.weld.osgi-bundle [45.0]
    import: (&(osgi.wiring.package=javax.annotation)(version>=1.1.0))
     |
    export: osgi.wiring.package=javax.annotation
  org.jboss.spec.javax.annotation.jboss-annotations-api_1.2_spec [39.0]

Chain 2:
  org.jboss.weld.osgi-bundle [45.0]
    import: (&(osgi.wiring.package=com.google.common.util.concurrent)(version>=13.0.0))
     |
    export: osgi.wiring.package=com.google.common.util.concurrent; uses:=javax.annotation
  com.google.guava [1.0]
    import: (osgi.wiring.package=javax.annotation)
     |
    export: osgi.wiring.package=javax.annotation
  org.apache.felix.framework [0])

我认为这是因为Java SE(v8)已经定义了一个包javax.annotation,但Java EE(v7)指定了带有更多注释的相同包。

I think it's because Java SE (v8) already defines a package "javax.annotation" but Java EE (v7) specifies the same package with more annotations.

javax.annotation已经被系统包作为系统包导出(org.apache.felix:org.apache.felix.framework:jar:4.2.1)。

"javax.annotation", however, is exported already as a system package by the system bundle (org.apache.felix:org.apache.felix.framework:jar:4.2.1).

在这种情况下,使OSGi从Java EE中选择一个的正确方法是什么?

What is the correct way in this case to make OSGi pick the one from Java EE instead?

编辑


  1. 仅添加JDK中真正需要的系统包

在这种情况下这是不可能的,因为我正在编写一个框架,而不是一个应用程序( Drombler FX )。

This is not possible in this case as I'm writing a framework, not an application (Drombler FX).

从org.osgi.framework.system.packages系统中排除javax.annotations de的财产fault.properties

实际上,我已经尝试过,因为我在框架中有一个default.properties的副本。它工作,但它似乎更像是一个黑客,并在我需要升级此文件时增加维护工作。此外,如果Maven Bundle Plugin在编译时检查导出的包(我会欢迎),当他们想要使用javax.annotations时,人们将不得不开始向他们的项目添加额外的依赖项,因为该包将由系统导出包裹了。
我希望找到更好的解决方案。

Actually, I've tried that already as I have a copy of default.properties in the framework anyway. It worked, but it seems more like a hack and increases the maintenance work when I need to upgrade this file. Also if ever the Maven Bundle Plugin checks the exported packages at compile time (which I would welcome), the people would have to start adding additional dependencies to their project when they want to use javax.annotations as that package would be exported by the system packages anymore. I was hoping to find a better solution.

使用背书机制

这看起来是迄今为止最干净的解决方案,但我仍然希望能避免这种情况,因为它会增加应用程序的打包复杂性。

This looked like the cleanest solution so far, but I still hoped I could avoid that, since it increases the application packaging complexity.

现在,我刚检查了Java SE 8文档,并且惊讶于JSR 250不再被列为支持技术!???它被列为Java SE 7中的认可技术。它们是否真的删除了Java SE 8中对JSR 250的认可支持或文档不正确?

Now, I just checked the Java SE 8 documentation and was surprised that JSR 250 is not listed as an endorsed technology anymore!??? It was listed as an endorsed technology in Java SE 7. Did they really remove the endorsed support for JSR 250 in Java SE 8 or is the documentation incorrect?

Java SE 8 : https://docs.oracle.com/javase/8/docs / techotes / guides / standards /

Java SE 8: https://docs.oracle.com/javase/8/docs/technotes/guides/standards/

Java SE 7: https://docs.oracle.com/javase/7/docs/technotes/guides/standards/

Java SE 7: https://docs.oracle.com/javase/7/docs/technotes/guides/standards/

如果Java SE 8仍然支持它,你对这种方法有什么看法?

If it is still supported in Java SE 8, what do you think about this approach?

任何其他方法?

推荐答案

Java的一个重大问题是越来越多的软件包被放入JDK应该是具有自己的版本生命周期的独立项目。这不会导致单一项目中出现问题,但会在OSGi中造成痛苦。

One of the big issues of Java is that more and more packages are put into the JDK that should be standalone project with its own versioning lifecycle. This does not cause a problem in monoholitic projects, but makes a pain within OSGi.

这就是为什么我们只添加JDK中真正需要的系统包而我们从捆绑中获取所有内容。您会惊讶地发现JDK实际需要多少包。

That is why we only add the system packages that are truly necessary from the JDK and we get everything from bundles. You will be surprised how much packages you actually need from the JDK.

如果有org.osgi.framework.system.packages.exclude系统,可以快速修复属性,但遗憾的是它不存在。

A quick fix could be if there was an org.osgi.framework.system.packages.exclude system property but sadly it does not exist.

如果指定 org.osgi.framework.system.packages 且没有包,则缓慢的解决方案是并且你会逐个找到你真正需要的包裹。如果你需要更少的软件包,你会感到惊讶。

A slow solution is if you specify the org.osgi.framework.system.packages with no packages and you find one-by-one which package you actually need. You will be surprised how less packages you will need.

如果你进入felix.jar,一个更快但更脏的解决方案是找到 default.properties 并复制出 org.osgi.framework.system.packages 系统属性的内容,但不包括 javax.annotation。* 类。当你意识到你将遇到与 javax.transaction。* 包相同的问题时,你需要得到 javax.sql。* 包来自捆绑...

A quicker but more dirty solution is if you get into felix.jar, find default.properties and copy out the content of the org.osgi.framework.system.packages system property with the exclusion of javax.annotation.* classes. By the time you will realize that you will have the same issue with javax.transaction.* packages and as an outcome, you will need to get javax.sql.* packages from a bundle...

遗憾的是,在felix中,您必须在系统包列表中列出osgi-core包。使用Equinox,不必列出这些软件包(在我看来这是好的,因为osgi-core软件包不应该是系统软件包配置的一部分)。

Sadly in felix you must list the osgi-core packages as well in the list of system packages. With Equinox, those packages do not have to be listed (which is good in my opinion as osgi-core packages should not be part of system packages configuration).

这篇关于OSGi:javax.annotation冲突:Java SE与Java EE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆