How to run XJC with Java 11 and maven?
Asked Answered
P

2

14

To generate java classes from XSD (for reading XML files), we used jaxb2-maven-plugin and Java8.

For java 11, we get many issues...

What libraries and plugins do work (today), allowing to generate java code from XSD using java 11 and maven? If possible point out different solutions, such as with cxf-xjc-plugin, jaxb2-Maven-Plugin and others.

Poetess answered 22/1, 2019 at 9:35 Comment(1)
Possible duplicate of XJC Maven Plugin(jaxb2-maven-plugin) Java 11 Migration IssuesThanatopsis
D
21

I've just investigated the same topic. The best way for Java 11 is to use cxf-xjc-plugin. It's a Maven plugin. No other Maven plugin is able to work under Java 11 without annoying workarounds.

I've published a complete example with cxf-xjc-plugin here: https://artofcode.wordpress.com/2019/02/28/generating-classes-from-xsd-under-java-11-the-right-way/

Drunken answered 1/3, 2019 at 22:47 Comment(2)
could you copy your solution here? would be perfect for others to find it.Poetess
I'd second that - I spent nearly two days trying to get the jaxb2 plugins to work. When I finally decided to change to CXF it took me about 1/2 hour and everything was working!!!Diapophysis
L
2

I was able to get Jaxb2-maven-plugin to work with Java 11. By default the generated classes will be created in the generated classes package. My only gripe is that it doesn't implement toString methods. If I ever figure that out i'll update this.

<dependency>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.5.0</version>
</dependency>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.5.0</version>
    <executions>
        <execution>
            <id>xjc-foo</id>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <sourceType>wsdl</sourceType>
                <sources>
                    <!-- if you put path only, it will read any wsdl or xsd file -->
                    <!-- if you have xsd that is imported in wsdl, then make sure you point it wsdl file -->
                    <source>${project.basedir}/src/main/resources/schemas/foo.wsdl</source>
                </sources>
                <clearOutputDir>false</clearOutputDir>
                <packageName>foo</packageName>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>javax.activation.api</artifactId>
            <version>1.2.0</version>
        </dependency>
    </dependencies>
</plugin>
Lippold answered 19/4, 2022 at 23:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.