maven-jaxb2-plugin 无法在 linux 机器上编译 xsd 但可以在 windows 上运行?

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

这是来自 pom.xml

的代码片段
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.8.3</version>
            </plugin>

这里是例外

   [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)

第一个XSD相关部分

<?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(嵌套 XSD)位置与 First XSD 相同。这是相关部分

<?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>

您是说通过本地文件导入模式适用于 Windows 但不适用于 Linux?这很奇怪,相对本地导入总是有效并且几乎出现在每个测试项目中。
这使我相信您的构建环境有问题。检查文件是否存在以及构建过程是否有权访问这些文件。

一般:

  • 使用较新的版本,当前为 0.12.3,您使用的 0.8.3 已超过 2 年。
  • 提供mvn -X -e clean install日志。
  • 提供一个最小的复现测试项目作为 PR here - for instance under e/emily (or whatever p/project-name you wish). Mind the lincense

我遇到了完全有效的 XSD 在 Linux 上编译失败但在 Windows 和 Mac 上运行的相同问题。我不得不像这样在 maven-jaxb-2 插件配置中关闭严格验证:

<configuration>
    <schemaDirectory>src/main/resources/xsd</schemaDirectory>
    <strict>false</strict>
    <extension>true</extension>
</configuration>