如何在maven-jaxb2-plugin中指定JAXB版本?
我需要使用最新版本的jaxb:2.2.4-1,但maven或maven-jaxb2-plugin似乎从JDK中选择了一个。
我尝试指定这样的版本:
<configuration>
<specVersion>2.2</specVersion>
...
</configuration>
但日志显示:
[INFO] [jaxb2:generate {execution: common}]
[INFO] Started execution.
[INFO] JAXB API is loaded from the [jar:file:/opt/jdk1.6.0_24/jre/lib/rt.jar!].
[INFO] Detected JAXB API version [2.1].
我尝试将依赖项添加到 javax.xml.bind:jaxb-api 和 com.sun.xml.bind:jaxb-impl 的正确版本,但这并没有帮助。
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.4-1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>common</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
我也尝试使用 maven-jaxb22-plugin 但它也不起作用。
I need to use the latest version jaxb: 2.2.4-1, but maven or maven-jaxb2-plugin seems to pick up the one from the JDK.
I tried specifying the version like this:
<configuration>
<specVersion>2.2</specVersion>
...
</configuration>
but the logs read:
[INFO] [jaxb2:generate {execution: common}]
[INFO] Started execution.
[INFO] JAXB API is loaded from the [jar:file:/opt/jdk1.6.0_24/jre/lib/rt.jar!].
[INFO] Detected JAXB API version [2.1].
I tried to add dependencies to the correct versions of javax.xml.bind:jaxb-api and com.sun.xml.bind:jaxb-impl, but that didn't help.
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.4-1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>common</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
I also tried using maven-jaxb22-plugin but it also didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下代码改编自 netbeans 生成的默认 web 应用程序。它使用依赖插件将 jar 复制到临时文件夹,并将该文件夹指定为编译器的认可目录,以便它覆盖 jdk 中的实现。
The following code is adapted from the default webapp that netbeans generates. It uses the dependency plugin to copy the jars to a temporary folder and specifies this folder as the endorsed directory to the compiler so it overrides the implementation in the jdk.
我尝试使用 Jörn 的解决方案,但看起来 maven-jaxb2-plugin 仍然继续使用 rt.jar 版本,因为我从插件中收到了告诉消息: [INFO] JAXB API is returned from the [jar:file :/C:/jdk1.6.0_25/jre/lib/rt.jar!]。
我的解决方案的不成功版本在如何使用依赖项插件方面略有不同,但这是成功构建的一部分......
I attempted to use Jörn's solution, but it looks like maven-jaxb2-plugin went ahead and used the rt.jar version anyway, as I got the telling message from the plugin: [INFO] JAXB API is loaded from the [jar:file:/C:/jdk1.6.0_25/jre/lib/rt.jar!].
My unsuccessful version of the solution is slightly different in how it uses the dependency plugin, but that's the one part of the build that succeeds...
嘿,我只是想节省人们的时间。
对于从事 jaxb-impl 工作的人来说,版本 jaxb-impl 2.2.4-1 旨在修复版本 2.2.4 的错误,META-INF 文件夹下的 istack-commons-runtime 的 pom 包含一个引用到它的父pom 2.4-SNAPSHOT,而它应该是2.4,因为这个版本不是快照。
因此,如果您不想使用快照,您将因此错误而崩溃,除非您想在本地存储库中添加所有内容,否则您可能必须手动将此版本更新到 jar 上的 pom 中。
干杯,
曼努埃尔.
hey just I want to save time of the people.
for the people who work on jaxb-impl, the version jaxb-impl 2.2.4-1 that meant to fix a bug of the version 2.2.4, the pom of istack-commons-runtime under the META-INF Folder contain a reference to its parent pom 2.4-SNAPSHOT when it should be jsut 2.4, due this version isn't a snapshot.
so if you don't want to work with snapshot you will smash with this error, unless you want to add everything on your local repository you may have to update manually this version into the pom on the jar.
cheers,
Manuel.