Search code examples
javamaven-3jaxb2maven-jaxb2-plugin

maven-jaxb2-plugin: Error in parsing schema location even when xsd and xjb files are in same location


I am having a pom.xml which looks like below:-

<?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>

    <parent>
        <groupId>com.eros</groupId>
        <artifactId>model</artifactId>
        <version>0.001-SNAPSHOT</version>
    </parent>

    <artifactId>nato-model</artifactId>
    <packaging>jar</packaging>
    <name>nato-model</name>

    <dependencies>
        <dependency>
            <groupId>com.eros</groupId>
            <artifactId>core-model</artifactId>
            <version>${main.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.1</version>
                <configuration>
                    <verbose>false</verbose>
                    <removeOldOutput>false</removeOldOutput>
                    <markGenerated>true</markGenerated>
                </configuration>

                <executions>

                    <execution>
                        <id>b</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generatePackage>com.eros.model.nato.n5k</generatePackage>
                            <generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
                            <schemaDirectory>
                                ${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds
                            </schemaDirectory>
                            <schemaIncludes>
                                <include>n5k.xsd</include>
                            </schemaIncludes>
                            <bindingDirectory>${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds</bindingDirectory>
                            <bindingIncludes>
                                <include>n5k.xjb</include>
                            </bindingIncludes>
                            <strict>false</strict>
                            <forceRegenerate>true</forceRegenerate>
                        </configuration>
                    </execution>
                    <execution>
                    <id>n7k</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generatePackage>com.eros.model.nato.n7k</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
                        <schemaDirectory>
                            ${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds
                        </schemaDirectory>
                        <schemaIncludes>
                            <include>n7k.xsd</include>
                        </schemaIncludes>
                        <bindingDirectory>${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds</bindingDirectory>
                        <strict>false</strict>
                        <forceRegenerate>true</forceRegenerate>
                    </configuration>
                </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

My n5k.xjb file looks like below:-

<?xml version="1.0" ?>
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" schemaLocation="./n5k.xsd">
        <jaxb:bindings>
            <jaxb:globalBindings typesafeEnumMaxMembers="1024"/>
        </jaxb:bindings>
</jaxb:bindings>

My n7k.xjb looks like below:-

<?xml version="1.0" ?>
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" schemaLocation="n7k.xsd">
        <jaxb:bindings>
            <jaxb:globalBindings typesafeEnumMaxMembers="1024"/>
        </jaxb:bindings>
</jaxb:bindings>

But on compiling I am getting the below error:-

Error while parsing schema(s).Location [ file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n5k.xjb{2,102}].
com.sun.istack.SAXParseException2; systemId: file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n5k.xjb; lineNumber: 2; columnNumber: 102; "file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n5k.xsd" is not a part of this compilation. Is this a mistake for "file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n7k.xsd"

Can someone let me know what I am doing wrong?

Environment:-

  • Java 8
  • Maven 3.5

Solution

  • I think the problem comes from the compilation of n7k.xsd. In the second execution you did not configure bindingIncludes. So apparently both n7k.xjb as well as n5k.xjb are used. And n5k.xjb references n5k.xsd which is not a part of this compilation.

    To resolve, try adding:

    <bindingIncludes>
        <include>n7k.xjb</include>
    </bindingIncludes>
    

    to the configuration of the second execution.