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

发布于 2024-11-30 04:57:58 字数 1831 浏览 2 评论 0原文

我需要使用最新版本的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜心 2024-12-07 04:57:58

以下代码改编自 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>

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>
猛虎独行 2024-12-07 04:57:58

我尝试使用 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!]。

我的解决方案的不成功版本在如何使用依赖项插件方面略有不同,但这是成功构建的一部分......

<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>

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

<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>
花想c 2024-12-07 04:57:58

嘿,我只是想节省人们的时间。
对于从事 jaxb-impl 工作的人来说,版本 jaxb-impl 2.2.4-1 旨在修复版本 2.2.4 的错误,META-INF 文件夹下的 istack-commons-runtime 的 pom 包含一个引用到它的父pom 2.4-SNAPSHOT,而它应该是2.4,因为这个版本不是快照。

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

因此,如果您不想使用快照,您将因此错误而崩溃,除非您想在本地存储库中添加所有内容,否则您可能必须手动将此版本更新到 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.

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文