如何在maven-jaxb2-plugin中指定JAXB版本? [英] How to specify the JAXB version in maven-jaxb2-plugin?
问题描述
我需要使用最新版本jaxb:2.2.4-1,但maven或maven-jaxb2-plugin似乎从JDK中选择了一个。
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>
但是日志显示为:
[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,但没有帮助。
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>
我也尝试过使用maven-jaxb22-plugin,但它也没有用。
I also tried using maven-jaxb22-plugin but it also didn't work.
推荐答案
以下代码改编自netbeans生成的默认webapp。它使用依赖插件将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.
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.4</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.4-1</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
这篇关于如何在maven-jaxb2-plugin中指定JAXB版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!