簡體   English   中英

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

[英]How to specify the JAXB version in maven-jaxb2-plugin?

我需要使用最新版本的 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,但是沒有幫助:

<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 但它也沒有用。

以下代碼改編自 netbeans 生成的默認 webapp。 它使用依賴插件將 jars 復制到一個臨時文件夾,並將該文件夾指定為編譯器的認可目錄,因此它會覆蓋 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>

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.]。

我不成功的解決方案版本在使用依賴插件的方式上略有不同,但這是構建成功的一部分......

<properties>
  <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
  <v.jaxb2-api>2.2.4</v.jaxb2-api>
  <v.jaxb2-impl>2.2.4-1</v.jaxb2-impl>
  <v.jaxb2-xjc>2.2.4-1</v.jaxb2-xjc>
  <v.jaxb2-basics-jaxb>2.1.13.MR2</v.jaxb2-basics-jaxb>
</properties>
...
<build>
  <plugins>
    <plugin>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-dependencies</id>
          <phase>validate</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <outputDirectory>${endorsed.dir}</outputDirectory>
            <excludeTransitive>true</excludeTransitive>
            <includeArtifactIds>jaxb-api,jaxb-impl</includeArtifactIds>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.3.2</version>
      <configuration>                        
        <source>1.6</source>
        <target>1.6</target>
        <fork>true</fork>
        <meminitial>256m</meminitial>
        <maxmem>768m</maxmem>
        <compilerArguments>
          <endorseddirs>${endorsed.dir}</endorseddirs>
        </compilerArguments>
      </configuration>
    </plugin>
  </plugins> 
</build>

嘿只是我想節省人們的時間。
對於從事 jaxb-impl 工作的人,版本 jaxb-impl 2.2.4-1 旨在修復版本 2.2.4 的錯誤,META-INF 文件夾下 istack-commons-runtime 的 pom 包含參考當它應該是 jsut 2.4 時,它的父 pom 2.4-SNAPSHOT,因為這個版本不是快照。

<parent>
    <groupId>com.sun.istack</groupId>
    <artifactId>istack-commons</artifactId>
    <version>2.4-SNAPSHOT</version>
</parent>

因此,如果您不想使用快照,則會出現此錯誤,除非您想在本地存儲庫中添加所有內容,否則您可能必須手動將此版本更新到 jar 上的 pom 中。 干杯,曼努埃爾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM