How can I generate classes from XSD that include another XSD

I have 2 projects:

xsdproject/
   src/main/resources/
      a.xsd
      b.xsd

implproject/

In implproject, I want to generate classes from xsd using the maven-jaxb2-plugin.

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <cleanPackageDirectories>true</cleanPackageDirectories>
                <forceRegenerate>true</forceRegenerate>
                <schemas>
                    <schema>
                        <dependencyResource>
                            <groupId>some.group</groupId>
                            <artifactId>xsdproject</artifactId>
                            <version>${project.version}</version>
                            <resource>a.xsd</resource>
                        </dependencyResource>
                    </schema>
                    <schema>
                        <dependencyResource>
                            <groupId>some.group</groupId>
                            <artifactId>xsdproject</artifactId>
                            <version>${project.version}</version>
                            <resource>b.xsd</resource>
                        </dependencyResource>
                    </schema>
                </schemas>
            </configuration>
        </plugin>

The problem here is β†’ b.xsd has

<xs:include schemaLocation="a.xsd" /> 

and during generation I have an error:

 Failed to read schema document 'a.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

Is there a way to successfully import 2 XSDs and compile them?

+4
source share
1 answer

Denial of responsibility. I am an author maven-jaxb2-plugin.

Try the following:

src/main/resources/catalog.cat:

REWRITE_SYSTEM "a.xsd" "maven:some.group:xsdproject:jar::!/a.xsd"

In configurationinpom.xml

<catalog>src/main/resource/catalog.cat</catalog>

(See Using Directories .)

I also think you only need to compile b.xsd. a.xsdshould be turned on automatically.

mvn -X clean install .

. :

, .

+2

All Articles