0

I am trying to get Maven to generate a JAXB binding using nested xml schemas: schema A imports schema B. Schema B imports schema C.

Everything builds just fine if objects in schema A reference objects in schema B that do not depend on a schema C object. If the object in schema B references an object in schema C it breaks. That is, going one level deep works. Going two deep does not.

As soon as I add an object in schema A that references an object in schema B, which in turn references an object in schema C, I get a org.xml.sax.SAXParseException: rc-resolve: Cannot resolve the name 'schemaB:objectInSchemaB' to a(n) 'type definition' component.

I can also build successfully if I omit the top level schema A, and start with just compiling schema B importing schema C. So again, the problem seems to be going more than one level deep with nested imports.

I'm stuck!

JAXB version:

Detected JAXB API version [2.2]. pluginArtifacts:[org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:maven-plugin:0.9.0:, org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-core:jar:0.9.0:compile, com.sun.org.apache.xml.internal:resolver:jar:20050927:compile, org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile, junit:junit:jar:4.8.1:compile, org.codehaus.plexus:plexus-utils:jar:1.5.15:compile, org.jvnet.jaxb2.maven2:maven-jaxb22-plugin:jar:0.9.0:compile, javax.xml.bind:jaxb-api:jar:2.2.7:compile, com.sun.xml.bind:jaxb-impl:jar:2.2.7:compile, com.sun.xml.bind:jaxb-core:jar:2.2.7:compile, com.sun.istack:istack-commons-runtime:jar:2.16:compile, com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:compile, javax.xml.bind:jsr173_api:jar:1.0:compile, com.sun.xml.bind:jaxb-xjc:jar:2.2.7:compile, org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.2:compile] specVersion:2.2

Below is my pom file:

<?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.example</groupId>
<artifactId>Example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaIncludes>
                            <schemaInclude>**/*.xsd</schemaInclude>
                        </schemaIncludes>
                        <strict>true</strict>
                        <verbose>true</verbose>
                        <extension>true</extension>
                        <removeOldOutput>true</removeOldOutput>
                        <specVersion>2.2</specVersion>
                        <episode>true</episode>
                        <episodeFile>${project.build.directory}/generated-sources/xjc/META-INF/jaxb-example.episode</episodeFile>
                    </configuration>
                    <id>jaxb-generate-example</id>
                </execution>
            </executions>
            <configuration>
                <catalog>src/main/resources/jaxb/catalog.xml</catalog>
                <catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver>
                <forceRegenerate>true</forceRegenerate>
                <generateDirectory>${project.build.directory}/generated-sources/xjc</generateDirectory>
                <verbose>true</verbose>
                <args>
                    <arg>-enableIntrospection</arg>
                </args>
            </configuration>
        </plugin>
    </plugins>
</build>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

"Schema A" below. If I comment out the baseSystemConfig object, then the schema compiles.

 <?xml version="1.0"?>   
 <xsd:schema version="1.0"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified"
           targetNamespace="http://ws.zwake.com/schema/zwakkiCentralCommon"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:zwakkiBase="http://ws.zwake.com/schema/zwakeBase"
           jaxb:version="2.1">
    <!-- Schema B import -->
    <xsd:import namespace="http://ws.zwake.com/schema/zwakeBase" schemaLocation="../ZwakeBase/zwakeBase.xsd"/>

    <xsd:annotation>
        <xsd:appinfo>
            <jaxb:globalBindings typesafeEnumMemberName="generateName"/>
        </xsd:appinfo>
    </xsd:annotation> 

    <xsd:element name="RetrieveBaseSystemConfigsRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="credentials" type="zwakkiBase:Credentials"/>
                <xsd:element name="restrictToBaseSystemIds" type="xsd:string" maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element> 
    <xsd:element name="RetrieveBaseSystemConfigsResponse">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="baseSystemConfig" type="zwakkiBase:ZwakeConfig" maxOccurs="unbounded"/>
                <xsd:element name="responseStatus" type="zwakkiBase:SystemError" minOccurs="1"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
Xstian
  • 8,184
  • 10
  • 42
  • 72
wakespeak
  • 20
  • 3
  • Which is the version of maven-jaxb2-plugin? Could you provide us your XSDs? – Xstian Apr 27 '15 at 09:12
  • Plugin version above. Schema B and C XSDs are very large. Let me see if I can post Schema A. – wakespeak Apr 27 '15 at 14:08
  • Each XSDs are placed in the same maven module? – Xstian Apr 27 '15 at 14:32
  • Yes, and the pom.xml line **/*.xsd allows them to be found at compile time as dependencies per the logging. – wakespeak Apr 27 '15 at 15:57
  • I tried your configuration using some example for your scenario .. and seems to work fine. If you can show us your XSDs. – Xstian Apr 27 '15 at 16:00
  • Found the problem: the object in schema B is an element. Changing the reference in schema A to ref= instead of type= resolved the problem. You pointed me in the right direction as I found it setting up another set of test schemas. – wakespeak Apr 27 '15 at 20:46
  • Perfect :) .. the most important thing is that you've solved the problem. Maybe add you an answer in order to close this topic. – Xstian Apr 27 '15 at 20:49

1 Answers1

1

I found the cause: I was pointing to an element instead of a complexType ('a type' as the compile error says) in the nested schema. This caused the compile failure. I needed to use a ref= instead of a type=, or change the schema B definitions.

So a case of the problem being too obvious to see initially. Thanks Xstian for confirming that otherwise it should have been working. This set me on the right path to find it.

wakespeak
  • 20
  • 3