简体   繁体   中英

maven-jaxb2-plugin not compiling xsd on linux machine but works on windows?

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>

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM