Generate Java classes from multiple XSDs with XJC

10,730

Solution 1

You want to try specifying the file for the XSD you're importing, as in:

<xsd:import namespace="http://www.myorg.com/base" schemaLocation="base.xsd"/>

This works well if you keep them side by side anyway. That way you can compile them in one operation.

If you want to run xjc separately (like they are built as separate modules), then you can use an episode file.

Solution 2

Have a look at "episodes": http://weblogs.java.net/blog/kohsuke/archive/2006/09/separate_compil.html

Share:
10,730

Related videos on Youtube

kavai77
Author by

kavai77

Java, what else?

Updated on June 05, 2022

Comments

  • kavai77
    kavai77 almost 2 years

    I have two xsd files:

    base.xsd:

    <schema
      targetNamespace="http://www.myorg.com/base"
      elementFormDefault="qualified"
      attributeFormDefault="unqualified"
      xmlns="http://www.w3.org/2001/XMLSchema">
    ...
    <complexType name="NrmClass">
        ...
    </complexType>
    ...
    </schema>
    

    main.xsd is a schema where we want to use a type from base.xsd

    <schema
      targetNamespace="http://www.myorg.com/main"
      elementFormDefault="qualified"
      xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:xn="http://www.myorg.com/base">
    
    <import namespace="http://www.myorg.com/base"/>
    ...
    <element>
      <complexType>
        <complexContent>
          <extension base="xn:NrmClass">
    ...
    
          </extension>
        </complexContent>
      </complexType>
    </element>
    ...
    </schema>
    

    When I try to compile both, I receive the following error:

    > xjc base.xsd main.xsd
    parsing a schema...
    [ERROR] src-resolve: Cannot resolve the name 'xn:NrmClass' to a(n) 'type definition' component.
      line 48 of file:/main.xsd
    

    What is wrong here?

  • kavai77
    kavai77 almost 12 years
    Thanks for the answer, it is definitely a good tip, but unfortunately even the example from the site is not working for me. I have posted another question: stackoverflow.com/questions/10532780/…