szarza
szarza

Reputation: 315

Is there any maven plugin for JAXB 3.0 (Jakarta EE 9)?

Current maven plugins like jaxb2-maven-plugin and maven-jaxb2-plugin generate code using the package javax.xml instead of the new jakarta.xml package of Jakarta XML Binding in Jakarta EE. It seems there's no way of configure any of them to use JAXB 3.0.

Is there any Maven plugin for JAXB 3.0?

Upvotes: 11

Views: 14132

Answers (6)

sendon1982
sendon1982

Reputation: 11274

I am using this to make it compatible with Java17

          <plugin>
            <groupId>org.jvnet.jaxb</groupId>
            <artifactId>jaxb-maven-plugin</artifactId>
            <version>4.0.8</version>
            <executions>
              <execution>
                <goals>
                  <goal>generate</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <schemaDirectory>src/main/xsd</schemaDirectory>
              <extension>true</extension>
              <!-- Plugins -->
              <args>
                <arg>-Xfluent-api</arg>
                <arg>-XtoString</arg>
                <arg>-Xequals</arg>
                <arg>-XhashCode</arg>
                <arg>-Xcopyable</arg>
              </args>
              <plugins>
                <plugin>
                  <groupId>org.jvnet.jaxb</groupId>
                  <artifactId>jaxb-plugins</artifactId>
                  <version>4.0.8</version>
                </plugin>

                <plugin>
                  <groupId>net.java.dev.jaxb2-commons</groupId>
                  <artifactId>jaxb-fluent-api</artifactId>
                  <version>2.1.8</version>
                </plugin>

              </plugins>

            </configuration>
          </plugin>

Also need add dependency for jakarta

      <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>3.0.1</version>
      </dependency>

      <!-- JAXB Runtime -->
      <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>3.0.1</version>
      </dependency>

      <dependency>
        <groupId>org.jvnet.jaxb</groupId>
        <artifactId>jaxb-plugins-runtime</artifactId>
        <version>4.0.8</version>
      </dependency>

Upvotes: 1

Martin
Martin

Reputation: 2981

The highsource project is active again and provides org.jvnet.jaxb:jaxb-maven-plugin, supporting JAXB 2.3, 3.0 and 4.x.

Upvotes: 0

Rick O&#39;Sullivan
Rick O&#39;Sullivan

Reputation: 476

Yes, the source/target (release) compatibility for the projects below is at Java 11, up from Java 8. And, JDK 17 is used for the build. JAXB dependencies are at version 4.x for Jakarta EE 10.

Here hisrc-higherjaxb-sample-jaxbplugins-2.1.0-mvn-src.zip is a sample project and to learn more see HiSrc Sample JAXB Plugins.

Note: The 4.x release of the JAXB API, RI and ZIP continues to use the latest JAXB Schema Binding 3.0 Specification.

Disclaimer: I am the maintainer for the forked HiSrc projects.

Upvotes: 6

Molossay Vladimir
Molossay Vladimir

Reputation: 29

There are currently three Maven plugins that can be used to generate code from XML schemas using JAXB 3.0:

  1. jakarta-jaxb-maven-plugin
  2. jaxb2-maven-plugin(a fork of the maven-jaxb2-plugin)
  3. org.jvnet.jaxb2_commons.maven_plugin

Upvotes: 1

gigermocas
gigermocas

Reputation: 190

https://github.com/evolvedbinary/jvnet-jaxb-maven-plugin is a fork of https://github.com/highsource/maven-jaxb2-plugin that adds jaxb3 support, and it's published on maven central.

Your mileage may vary with jaxb2-basics depending on the specific plugin, as it doesn't support jaxb3 at the moment.

Upvotes: 2

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16115

jaxb2-maven-plugin version 3.0.0 will support JAXB 3. It doesn't seem to be available yet on Maven repositories, but you can get it on github and install it locally.

Remark: the previous versions almost work (you just need to change their dependencies versions), but unfortunately AbstractJaxbMojo preloads some JAXB classes by name and these names changed.

Upvotes: 4

Related Questions