How to specify the JAXB version in maven-jaxb2-plugin?
Asked Answered
E

3

6

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.

Edy answered 17/8, 2011 at 14:31 Comment(0)
H
2

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>
Heidelberg answered 18/8, 2011 at 12:47 Comment(2)
Interesting idea. I'll try it. Meanwhile, I reverted to using antrun... It works but it's not very nice.Edy
I've tried this approach as well, and even using the specific maven-jaxb22-plugin but I'm still getting the JDK-detected version.Vera
E
0

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>
Elasmobranch answered 13/10, 2011 at 21:10 Comment(1)
Try running maven with debug info (option -X) to see what happens. This might give you an idea where's the problem and how to fix it.Edy
F
0

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.

Forethoughtful answered 12/1, 2012 at 1:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.