0

Here is code snippet from pom.xml

            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.8.3</version>
            </plugin>

Here is the exception

   [INFO] --- maven-jaxb2-plugin:0.8.3:generate (default) @ customer-project ---
   [ERROR] Error while parsing schema(s).Location [ file:....Customer.xsd{12,97}].
    org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'customer:CustomerApplication' to a(n) 'element declaration' component.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:2537)

First XSD relevant part

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.cohbe.org/CustomerRequest"
            xmlns:customer="http://www.cohbe.org/customer"
            targetNamespace="http://www.cohbe.org/CustomerRequest"
            elementFormDefault="qualified">
    <xsd:import schemaLocation="CustomerDetails.xsd"
              namespace="http://www.cohbe.org/customer"/>
    <xsd:element name="CustomerNewRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="customer:CustomerApplicationDetail" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    ...
</xsd:schema>

CustomerDetails.xsd(Nested XSD) location is same as of First XSD. Here is relevant part

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema version="2.15" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.cohbe.org/customer"
            targetNamespace="http://www.cohbe.org/customer"
            xmlns:countries="http://www.cohbe.org/Counties"
            elementFormDefault="qualified">
    <!-- Version 2.15 -->
    <xsd:import namespace="http://www.cohbe.org/states" schemaLocation="States.xsd"/>
    <xsd:element name="CustomerApplicationDetail"
               type="CustomerApplicationDetail"/>
    <xsd:complexType name="CustomerApplicationDetail">

    .....
    </xsd:schema>
emilly
  • 10,060
  • 33
  • 97
  • 172

2 Answers2

2

I had the same issue where perfectly valid XSDs failed to compile on Linux but worked on Windows and Mac. I had to turn off strict validation in the maven-jaxb-2 plugin configuration like so :

<configuration>
    <schemaDirectory>src/main/resources/xsd</schemaDirectory>
    <strict>false</strict>
    <extension>true</extension>
</configuration>
SpareTheRod
  • 476
  • 6
  • 13
1

You're saying a schema import via local file works on Windows but not Linux? This is strange, relative local imports always work and present in almost every test project.
This leads me to believe that you have a problem with your build environment. Check that the files are present and that the build process has permissions to access the files.

General:

  • Use a newer version, current is 0.12.3, you're using 0.8.3 which is more than 2 years old.
  • Provide mvn -X -e clean install log.
  • Provide a minimal reproducing test project as PR here - for instance under e/emily (or whatever p/project-name you wish). Mind the lincense
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • I used 0.12.3 also but same result.i tried mvn -X -e clean install but does not have extra information. Files are also present – emilly Jun 20 '15 at 08:38
  • But I am not sure how can I check whether build process has permission to access that file or not ? – emilly Jun 20 '15 at 08:39
  • Still, consider providing that log. Maybe we'll see something you don't see. How to check permissions - try compiling *just* `Customer.xsd`. Finally, it's a situation where it is hard to help without seeing your files. If you need support, please follow the steps I've described above. – lexicore Jun 20 '15 at 13:26
  • see http://stackoverflow.com/questions/30955100/cannot-resolve-the-name-to-an-element-declaration-component. I can reproduce it on windows machine also if I remove `` from second xsd file. Then I tried using type instead of ref as suggested at http://www.xfront.com/ZeroOneOrManyNamespaces.html but then get `One of 'ref' or 'name' must be present in a local element declaration.` – emilly Jun 20 '15 at 14:34
  • Can you please have a look at http://stackoverflow.com/questions/31293874/generate-java-class-based-on-xsd-without-block-substitution. I tried with maven-jaxb2-plugin true src/main/resources/META-INF/schema but it does not work. Thanks in advance – emilly Jul 08 '15 at 15:35
  • can you please have a look at http://stackoverflow.com/questions/31293874/generate-java-class-based-on-xsd-without-block-substitution as I am not sure how to proceed here ? – emilly Jul 09 '15 at 08:08