如何在maven-jaxb2-plugin中指定JAXB版本?

iva*_*ant 5 maven-2 jaxb2 maven maven-jaxb2-plugin

我需要使用最新版本jaxb:2.2.4-1,但maven或maven-jaxb2-plugin似乎从JDK中获取了一个.

我尝试指定这样的版本:

<configuration>
    <specVersion>2.2</specVersion>
    ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是日志显示:

[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].
Run Code Online (Sandbox Code Playgroud)

我试图将依赖项添加到正确版本的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>
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用maven-jaxb22-plugin但它也没用.

Jör*_*ann 2

以下代码改编自 netbeans 生成的默认 web 应用程序。它使用依赖插件将 jar 复制到临时文件夹,并将该文件夹指定为编译器的认可目录,以便它覆盖 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>
Run Code Online (Sandbox Code Playgroud)