简体   繁体   English

将JAXB声明为依赖项。 为什么?

[英]Declaring JAXB as a dependency. Why?

Why would you want to declare JAXB as a dependency of your Java application since it's anyway shipped with the JRE and cannot be overriden in your applications classpath? 为什么要将JAXB声明为Java应用程序的依赖项,因为它无论如何随JRE一起提供,并且无法在应用程序类路径中覆盖?

Using the jersey-json as an example, in their POM file they declare a dependency to jaxb-impl without specifying the exact version even. jersey-json为例,在他们的POM文件中,他们声明了对jaxb-impl的依赖,而没有指定确切的版本。 What are they gaining by doing this? 他们通过这样做获得了什么?

And also, when I add a dependency to jersey-json in my own POM file, I end up having jaxb-api.jar and jaxb-impl.jar in my classpath. 而且,当我在自己的POM文件中向jersey-json添加依赖项时,我最终在我的类路径中使用了jaxb-api.jar和jaxb-impl.jar。 Why would I want this to happen? 我为什么要这样呢? Isn't the default JVM implementation anyway getting loaded if I don't put the files to the endorsed libraries directory? 如果我不将文件放到endorsed libraries目录中,是不是默认的JVM实现被加载?

I'm seeing in the linked pom: 我在链接的pom中看到了:

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
    </dependency>

But there is also a parent pom, so you might want to follow that trail up, to see if an actual version and/or scope was specified there (and propagated down). 但是也有一个父pom,所以你可能想要跟踪该跟踪,看看是否在那里指定了实际的版本和/或范围(并向下传播)。

But if it isn't, then I'm guessing the Jersey team felt that the JAXB 2 API is mature enough to allow them to specify a loose dependency on the JAXB implementation. 但如果不是,那么我猜测Jersey团队认为JAXB 2 API足够成熟,允许他们指定对JAXB实现的松散依赖。

The JRE ships with a specific implementation of the JAXB impl, which was equivalent to JAXB RI 2.1.7 for the longest time. JRE附带了JAXB impl的特定实现,它最长时间等同于JAXB RI 2.1.7。 But at the same time, there is a mechanism to easily swap out for another implementation of your choice, in your apps. 但与此同时,还有一种机制可以在您的应用中轻松换出您选择的其他实现。

Sure you can use the built-in JRE JAXB implementation, and if it works for your app, you surely should try. 当然你可以使用内置的JRE JAXB实现,如果它适用于你的应用程序,你一定要尝试。

Nonetheless, some reasons that could lead you to want a separate JAXB implementation include : a left-over bug (addressed in a newer release); 尽管如此,可能导致您需要单独的JAXB实现的一些原因包括:遗留错误(在较新版本中解决); need a newer JAXB API such as JAXB 2.2.x (which comes in more recent version of the JRE); 需要更新的JAXB API,例如JAXB 2.2.x(更新版本的JRE); want to use a different implementation altogether (because it happens to have a better API and/or performance for your particular usage), etc... 想要完全使用不同的实现(因为它恰好具有更好的API和/或特定用途的性能),等等......

So back to your jersey question, I'm guessing again that they wanted to give developers the flexibility to pull in their JAXB impl of choice. 回到你的球衣问题,我再次猜测他们想让开发人员灵活地选择他们的JAXB impl。 I'd think they have some level of recommendations somewhere in their guides. 我认为他们在导游的某处有一些建议。 However, the fact that the JAXB RI is specifically marked as a dependency, undercuts the argument. 但是,JAXB RI被特别标记为依赖关系的事实削弱了该论点。

That sound like the jersey people defined their dependency wrong. 这听起来就像球衣人们认为他们的依赖性错了。 If a dependency is provided by the environment where you run it should be defined with the scope "provided". 如果运行环境提供了依赖关系,则应使用“提供”范围定义依赖关系。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用处理依赖性运行 Java 程序时出错。 StringIndexOutOfBoundsException - Error running java program using processing dependency. StringIndexOutOfBoundsException Maven构建成功,但是缺少依赖项。 JDWP退出错误 - Maven build is successful but missing a dependency. JDWP exit error JAXB定位器 - 缺少依赖? - JAXB Locator - missing dependency? 未找到依赖项:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。 依赖注解: - No found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 在 Play 中声明测试依赖! - Declaring a Test Dependency in Play! JcaPEMKeyConverter 由 BouncyCastle 提供,这是一个可选依赖项。 要使用对 EC 密钥的支持,您必须显式地将依赖项添加到类路径 - JcaPEMKeyConverter is provided by BouncyCastle, an optional dependency. To use support for EC Keys you must explicitly add dependency to classpath Spring + Hibernate的。 创建bean时出错。 不满意的依赖。 无法弄清楚注释是不对的 - Spring+Hibernate. Error creating bean. Unsatisfied dependency. Cannot figure out what annotation is not right 在Spring中声明一个explict对象依赖项 - Declaring an explict object dependency in Spring 如何找出我的maven pom中的哪些依赖项具有特定的依赖项。 - How to find out what dependencies in my maven pom have a particular dependency. Spring - 无法导入 spring-cloud-config-client 依赖项。 IntellliJ 错误 - Spring - Cannot import spring-cloud-config-client dependency. IntellliJ Bug
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM