0

I have been looking around a lot regarding this issue. I found some suggestions, but I cannot make them work, so maybe I'm doing something wrong.

Problem

I have inter-depending XSDs in the same maven project. I have commonA.xsd & commonB.xsd which have generic types and I have a specific.xsd which references those two. The problem is that I cannot make the hierarchical generation work.

My current pom.xml

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.3</version>
    <executions>
        <execution>
            <id>base</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaIncludes>
                    <include>commonA.xsd</include>
                    <include>commonB.xsd</include>
                </schemaIncludes>
                <generatePackage>common</generatePackage>
                <generateDirectory>${project.build.directory}/generated-sources/xjc-common</generateDirectory>
            </configuration>
        </execution>

        <execution>
            <id>specific</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaIncludes>
                    <include>specific.xsd</include>
                </schemaIncludes>
                <generatePackage>specific</generatePackage>
                <generateDirectory>${project.build.directory}/generated-sources/xjc-specific</generateDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Attempted solutions

Referencing the episode file

I found this page https://stackoverflow.com/a/11135186/284263 where it is proposed to reference the episode file.
[ERROR] Error while parsing schema(s).Location [ file:/path/to/xsd/COMMONA.XSD{122,60}].com.sun.istack.SAXParseException2; systemId: file:/path/to/xsd/COMMONA.XSD; lineNumber: 122; columnNumber: 60; (the above customization is attached to the following location in the schema)
This didn't work for me and it also feels a bit hacky.

Create a bindings.xjb

I also looked into this answer https://stackoverflow.com/a/22559100/284263. I cannot find any 'real' examples anywhere, and I don't know if this is the correct approach anyway for my case.

Referring to maven artifact

I found in the plugin's documentation that I can do something like this:

<episodes>
    <episode>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin-tests-po</artifactId>
        <!--  Version of the artifact. May be omitted.
        The plugin will then try to find the version using
        the dependencyManagement and dependencies of the project. -->
        <version>${project.version}</version>
    </episode>
</episodes>

This is an external reference, as far as I understand. It doesn't work, because the artifact doesn't exist in the repo yet, e.g. when developing and having a SNAPSHOT version, or might be risky because it will refer an older version.

Any suggestions or corrections?
Thanks for your time.

Community
  • 1
  • 1
Dimitrios K.
  • 1,008
  • 13
  • 36
  • You actually did not state the problem. You just said you have a specific schema referencing two common schemas. What is the problem? – lexicore May 06 '15 at 10:32
  • Hey lexicore. The problem is that I cannot make the hierarchical generation work. I changed the question to reflect this. – Dimitrios K. May 06 '15 at 10:59
  • By "hierarchical" you mean that the second execution should use classes from the first execution? – lexicore May 06 '15 at 16:13
  • Yes. The 2 'commons' XSDs generate the common classes and the specific XSD uses them. – Dimitrios K. May 06 '15 at 16:20

0 Answers0