Import namespace - Cannot resolve the name to a(n) 'type definition' component

14,341

Ok figured out the work-around:

I moved all the dependent xsd's (that the problematic xsd's references) plus a bunch of other un-used xsds to a separate folder and then re-generated code using maven - it works now. It appears that there was some namespace conflict with one of the other un-used xsd's i haven't yet pointed out the specific one.

Share:
14,341
crazy horse
Author by

crazy horse

Updated on June 04, 2022

Comments

  • crazy horse
    crazy horse almost 2 years

    Context: I am generating java classes from xsd files using maven-jaxb plugin. All my .xsd files are in a single location - src/main/resource directory.

    Problem: Everything works fine when xsd's don't reference/import other xsd's with a different target namespace. However when the following xsd below (with targetNamespace="http://www.companyA.com/someservice") imports another xsd filename.xsd from a different namespace (namespace="http://www.companyB.com/"), I get the above error: Cannot resolve the name xxx to a(n) 'type definition' component.

    Edit: the element name in the current xsd file is 'entityName', and its type is "companyB:entityName" (i.e.) the names are the same.

    I then tried invoking xjc on this file from the command line and this generated Java classes correctly. I also made sure that in Eclipse, I am able to ctrl-click/examine source on "type="companyCdm:entityName", which correctly opens the filename.xsd file. However for some reason maven is unable to get to it.

    Question: What am I missing? Why is this case (2 namespaces) different from dealing with a single namespace?

    Here is my XSD:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns="http://www.companyA.com/someservice"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:companyB="http://www.companyB.com/version"
        targetNamespace="http://www.companyA.com/someservice"
        elementFormDefault="qualified" attributeFormDefault="qualified">
    
        <xsd:import namespace="http://www.companyB.com/version" schemaLocation="filename.xsd" />
    
        <xsd:element name="MyName" type="MyType" />
    
        <xsd:complexType name="MyType">
            <xsd:annotation>
            <xsd:documentation>
                A list
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="entityName" type="companyB:entityName" maxOccurs="1" minOccurs="1"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>