How to run cxf-xjc-plugin with Spring-Boot?

2.8k views Asked by At

I'm trying to set up a simple project that should generate xsdtojava using cxf-xjc-plugin. The project also uses spring-boot.

Result during mvn package:

[INFO] Building jar: /tmp/cxf-xjc-plugin3386923426289303800.jar
[DEBUG] Error: Could not find or load main class org.apache.cxf.maven_plugin.XSDToJavaRunner
[DEBUG] Caused by: java.lang.ClassNotFoundException: org.apache.cxf.maven_plugin.XSDToJavaRunner

This is strange, because on classpath I can clearly see the XSDToJavaRunner.class.

My java project dir is: javaExecutable = /usr/lib/jvm/java-11-openjdk-amd64/bin/java, and

java -version shows: OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)

I tried throwing the cxf-xjc-plugin, several jaxb-* libraries into <dependency> maven node as follows, but the error remains the same. What am I missing here?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>cxfxjc-test</artifactId>
    <version>1.0.0</version>

    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.0.5.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-core</artifactId>
            <version>3.2.6</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-xjc-plugin</artifactId>
            <version>3.2.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                        <configuration>
                            <xsdOptions>
                                <xsdOption>
                                    <xsd>src/main/resources/test.xsd</xsd>
                                </xsdOption>
                            </xsdOptions>
                        </configuration>
                    </execution>
                </executions>

                <dependencies>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-xjc-plugin</artifactId>
                        <version>3.2.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
1

There are 1 answers

0
dexter125 On

Looks like it was some issue with Java on Ubuntu. Todays update to OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode) fixed this.

Before update - cxf plugin was always running in forked mode and it failed to properly create jar archive in /tmp/. There was no issue with write rights etc. but for some reason there were no jars in this archive and this is why you got ClassNotFoundException.