java 如何让 maven 在 JDK 中使用不同的 JAXB 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7838675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get maven to use a different JAXB library to one in JDK
提问by Dave Richardson
I'm using java 1.6.0_14 which includes an implementation of the annotation javax.xml.bind.annotation.XmlElement
. However the one in the JDK only applies to Method and Field.
我正在使用 java 1.6.0_14 ,其中包括 annotation 的实现javax.xml.bind.annotation.XmlElement
。但是 JDK 中的那个只适用于 Method 和 Field。
I've found jaxb-api.jar version 2.2.3 permits this on Parameter too, so I want to use this version.
我发现 jaxb-api.jar 版本 2.2.3 也允许在 Parameter 上使用这个,所以我想使用这个版本。
Problem is, I can't figure out how to get maven to use this one in preference to the one in the JDK so that when I am writing my code it doesn't complain that the annotation is being used in an invalid location.
问题是,我不知道如何让 maven 优先使用这个而不是 JDK 中的那个,这样当我编写我的代码时,它不会抱怨在无效位置使用了注释。
Any suggestions?
有什么建议?
采纳答案by Nicola Musatti
Include an explicit dependency in your POM:
在 POM 中包含显式依赖项:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.3</version>
</dependency>
回答by emmmdeee
You have to use the Java endorsed override mechanism. I got this directly from the Apache CXF website.
您必须使用 Java 认可的覆盖机制。我直接从 Apache CXF 网站上得到了这个。
JAXB is the default data binding for CXF. If you don't specify one of the other data bindings in your Spring configuration or through the API, you will get JAXB. Releases of CXF since 2.3.x have used the JDK7 default of JAXB 2.2, however Maven users running on JDK 6 will need to use the Java endorsed override mechanism to use JAXB 2.2 instead of JAXB 2.1.
JAXB 是 CXF 的默认数据绑定。如果您没有在 Spring 配置中或通过 API 指定其他数据绑定之一,您将获得 JAXB。自 2.3.x 以来的 CXF 版本使用 JAXB 2.2 的 JDK7 默认值,但是在 JDK 6 上运行的 Maven 用户将需要使用 Java 认可的覆盖机制来使用 JAXB 2.2 而不是 JAXB 2.1。
http://cxf.apache.org/docs/jaxb.htmlfirst paragraph at the top. You basically download the new version of jaxb then tell the JRE/JDK to load that instead of the default implementation that it shipped with.
http://cxf.apache.org/docs/jaxb.html顶部的第一段。您基本上下载了 jaxb 的新版本,然后告诉 JRE/JDK 加载它而不是它附带的默认实现。