虽然在Windows上maven在Linux服务器上构建,但我遇到了错误 机器工作正常
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)
以下是pom.xml的相关摘录
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<schemaDirectory>src/main/resources/META-INF/schema</schemaDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
第一个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位置与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/CustDetails"
targetNamespace="http://www.cohbe.org/CustDetails"
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>
更新: - 第二个文件属性为: -
xmlns="http://www.cohbe.org/customer"
targetNamespace="http://www.cohbe.org/customer"
而不是
xmlns="http://www.cohbe.org/CustDetails"
targetNamespace="http://www.cohbe.org/CustDetails"
这个问题是复制/粘贴错误所以我得到了同样的错误,即org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name