-1

I am getting the following error upon building my project in Java 11:

[INFO] Created EpisodePath [XXXX/src/main/java/META-INF/JAXB]: true
[INFO] Ignored given or default xjbSources [XXXX/src/main/xjb], since it is not an existent file or directory.
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.5.0:xjc (xjc) on project XXXX: Prefix '' is already bound to ''
I have researched the issue thoroughly and implemented the suggestions I have found, but with no luck.

Considerations:

  • I am trying to maintain compatibility with Java 8 and Java 11, so that my app can be built to Java 8 and runnable on both 8 and 11.
  • I have adopted (JAXB 3.0.0) for this reason.
  • The jaxb2-maven-plugin versions available to me are: 1.5.0, 2.3.0, 2.3.1, and 2.5.0 (can't use 3.2.0 due to older Maven).
  • I have tried jaxb-xjc-3.1.0-M1 and 4.0.0 in addition to the one in my POM, and get the same error.

Please let me know if there is anything I can clarify. Any help much appreciated.

POM:

<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>
    <artifactId>XXXXXXXXXX</artifactId>
    <packaging>jar</packaging>
    <name>XXXXXXXXX</name>

    <parent>
        <groupId>XXXXXXXX</groupId>
        <artifactId>XXXXXXXX</artifactId>
        <version>XXXXXXXX</version>
    </parent>
    
    <properties>
        <jakarta.activation.version>2.0.0</jakarta.activation.version>
        <jakarta.xml.bind-api.version>3.0.0</jakarta.xml.bind-api.version>
        <jaxb-impl.version>3.0.0</jaxb-impl.version>
        <jaxb-runtime.version>3.0.0</jaxb-runtime.version>
        <jaxb-xjc.version>3.0.0</jaxb-xjc.version>
        <validation-api.version>2.0.1.Final</validation-api.version>
        <hibernate-validator.version>6.2.5.Final</hibernate-validator.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>${jakarta.xml.bind-api.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <scope>runtime</scope>
            <version>${jaxb-impl.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>${jaxb-runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${validation-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate-validator.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <!-- exclude xsd/xml from jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>*.xml</exclude>
                        <exclude>*.xsd</exclude>
                    </excludes>
                </configuration>
            </plugin>
            
            <plugin>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*.xsd</include>
                    </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                        <packageName>XXXXXXXXX</packageName>
                        <sources>
                            <source>${project.basedir}/src/main/resources/TD.xsd</source>
                        </sources>
                        <!-- so we keep the src/main/java/.gitignore file which otherwise will 
                            be deleted -->
                        <clearOutputDir>false</clearOutputDir>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.sun.activation</groupId>
                        <artifactId>jakarta.activation</artifactId>
                        <version>${jakarta.activation.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>jakarta.xml.bind</groupId>
                        <artifactId>jakarta.xml.bind-api</artifactId>
                        <version>${jakarta.xml.bind-api.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>com.sun.xml.bind</groupId>
                        <artifactId>jaxb-impl</artifactId>
                        <version>${jaxb-impl.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.glassfish.jaxb</groupId>
                        <artifactId>jaxb-xjc</artifactId>
                        <version>${jaxb-xjc.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
2
  • By “JAXB 3.0.0”, do you mean Jakarta XML Binding 3.0? Commented Aug 7, 2024 at 19:04
  • Why not use latest Maven 3? That still runs on Java 8 AFAIK. Commented Aug 7, 2024 at 19:46

1 Answer 1

1

If you're looking for a similar plugin that supports java 8 and jaxb3, you could look at jaxb-tools with v3

Here is the translated configuration of your actual plugin :

<plugin>
    <groupId>org.jvnet.jaxb</groupId>
    <artifactId>jaxb-maven-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
        <execution>
            <id>xjc</id>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- <outputDirectory>${project.basedir}/src/main/java</outputDirectory> -->
        <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
        <!--<packageName>XXXXXXXXX</packageName>-->
        <generatePackage>XXXXXXXXX</generatePackage>
        <!-- <sources><source>${project.basedir}/src/main/resources/TD.xsd</source></sources> -->
        <schemas>
            <schema>
                <fileset>
                    <directory>${basedir}/src/main/resources</directory>
                    <includes>
                        <include>TD.xsd</include>
                    </includes>
                </fileset>
            </schema>
        </schemas>
        <!-- <clearOutputDir>false</clearOutputDir> -->
        <removeOldOutput>false</removeOldOutput>
    </configuration>
</plugin>

One advice : don't generate sources under src/main/java but generate it under the target directory (default for the plugin is ${project.build.directory}/generated-sources/xjc) : it won't be included in your git repository and will be generated only when necessary.
Moreover, it will be included as source root folder by the plugin itself, so it will be used by the maven-compiler plugin to generate the associated .class files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.