jaxb2-maven-plugin:2.2:xjc - 未声明的前缀问题 - java 1.7

jaxb2-maven-plugin:2.2:xjc - Undeclared Prefix Issue - java 1.7

我在 pom.xml

中使用了以下依赖项
<dependency>
     <groupId>com.sun.xml.bind</groupId>
     <artifactId>jaxb-xjc</artifactId>
     <version>2.1.14</version>
     <scope>compile</scope>
 </dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.7</version>
   <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.7</version>
    <scope>compile</scope>
</dependency>
 <dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.0</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>com.thoughtworks.xstream</groupId>
  <artifactId>xstream</artifactId>
  <version>1.3.1</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>xerces</groupId>
  <artifactId>xercesImpl</artifactId>
  <version>2.11.0</version>
  <scope>runtime</scope>
</dependency>
<dependency>
   <groupId>xml-apis</groupId>
   <artifactId>xml-apis</artifactId>
   <version>2.0.2</version>
   <scope>compile</scope>
</dependency>

binding.xjb :

 <jxb:bindings version="1.0"
           xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

 <jxb:bindings schemaLocation="../../../../xsd/icmarchitecture/mom/log/RetrieveExecutionInfo.xsd" node="/xs:schema">
<jxb:globalBindings>
    <jxb:javaType name="com.pcm.icm.architecture.util.Timestamp" xmlType="icm:Timestamp" printMethod="toXsdString" parseMethod="create"/>
</jxb:globalBindings>

RetrieveExecutionInfo.xsd :

                     <?xml version="1.0" encoding="UTF-8"?>
                     <!-- edited with XMLSPY v2004 rel. 2 U (http://www.xmlspy.com) by pcm (pcm) -->
                     <!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by bbl (bbl) -->
                  <xs:schema 
        targetNamespace="http://www.pcm.com/icm/architecture/mom/log/payload" 
       xmlns="http://www.pcm.com/icm/architecture/mom/log/payload" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        xmlns:ns1="http://www.pcm.com/icm/architecture/status/payload" 
       xmlns:icm="http://www.pcm.com/icm/architecture/common/payload" 
     elementFormDefault="qualified" attributeFormDefault="qualified">
               <xs:import 
        namespace="http://www.pcm.com/icm/architecture/status/payload" 
        schemaLocation="../../status/status.xsd"/>
                <xs:import 
         namespace="http://www.pcm.com/icm/architecture/common/payload" 
         schemaLocation="../../common/ICMTypedefinitions.xsd"/>
                <xs:complexType name="FilterKeyValueType">
               <xs:annotation>
                <xs:documentation>Filter on key value pair</xs:documentation>
              </xs:annotation>
    <xs:sequence>
        <xs:element name="Key" type="xs:string"/>
        <xs:element ref="Operator"/>
        <xs:element name="Value" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="FilterKey">
    <xs:annotation>
        <xs:documentation>Filter on Key</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="Operator"/>
            <xs:element name="Value" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType name="KeyValueType">
    <xs:annotation>
        <xs:documentation>Key value pair</xs:documentation>
    </xs:annotation>
    <xs:sequence>
        <xs:element name="Key" type="xs:string"/>
        <xs:element name="Value" type="xs:string" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="Operator">
    <xs:annotation>
        <xs:documentation>Operator for a filter</xs:documentation>
    </xs:annotation>
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="greater_equal"/>
            <xs:enumeration value="greater"/>
            <xs:enumeration value="less"/>
            <xs:enumeration value="less_equal"/>
            <xs:enumeration value="not_equal"/>
            <xs:enumeration value="equal"/>
            <xs:enumeration value="like"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>
<xs:element name="FilterService">
    <xs:annotation>
        <xs:documentation>Filter on service</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="ServiceAddress"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="FilterTimestamp">
    <xs:annotation>
        <xs:documentation>Filter on timestamp</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="Operator"/>
            <xs:element name="Value" type="icm:Timestamp"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="ExecutionInfoElement">
    <xs:annotation>
        <xs:documentation>Reply element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="ServiceAddress"/>
            <xs:element name="RequestTimestamp" type="icm:Timestamp" minOccurs="0"/>
            <xs:element name="DurationInMillis" type="xs:long" minOccurs="0"/>
            <xs:element name="RequestLogMsgId" type="xs:string" minOccurs="0"/>
            <xs:element name="KeyValue" type="KeyValueType" minOccurs="0" maxOccurs="999"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="FilterMillis">
    <xs:annotation>
        <xs:documentation>Filter on millis</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="Operator"/>
            <xs:element name="Value" type="xs:long"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="ServiceAddress">
    <xs:annotation>
        <xs:documentation>Service address</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element name="service" type="xs:string" minOccurs="0"/>
            <xs:element name="protocol" type="xs:string" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:string" use="optional"/>
    </xs:complexType>
</xs:element>
<xs:element name="RetrieveExecutionInfoRq">
    <xs:annotation>
        <xs:documentation>Request to get execution info elements</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="FilterService" minOccurs="0" maxOccurs="999"/>
            <xs:element ref="FilterTimestamp" minOccurs="0" maxOccurs="999"/>
            <xs:element ref="FilterMillis" minOccurs="0" maxOccurs="999"/>
            <xs:element name="AndFilterKeyValue" type="FilterKeyValueType" minOccurs="0" maxOccurs="999"/>
            <xs:element name="OrFilterKeyValue" type="FilterKeyValueType" minOccurs="0" maxOccurs="999"/>
            <xs:element ref="FilterKey" minOccurs="0" maxOccurs="999"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="RetrieveExecutionInfoRs">
    <xs:annotation>
        <xs:documentation>Reply with execution info elements</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element name="statusInfo" type="ns1:statusType"/>
            <xs:element ref="ExecutionInfoElement" minOccurs="0" maxOccurs="999"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
      </xs:schema>

Maven 版本 - 3.1 Java 版本 - 1.7

错误:

org.xml.sax.SAXParseException; systemId: 文件:/C:/Data/NewGitRepo/TestICMGitRepo/ICMTrunk/icmarchitecture/src/main/resources/xjb/icmarchitecture/mom/log/binding.xjb;行号:7;列数:136; UndeclaredPrefix:无法将 'icm:Timestamp' 解析为 QName:未声明前缀 'icm'。 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198) 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)

org.xml.sax.SAXParseException; systemId: 文件:/binding.xjb;行号:7;列数:136; cvc-attribute.3: 元素 'jxb:javaType' 上属性 'xmlType' 的值 'icm:Timestamp' 就其类型 'QName' 而言无效。 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198) 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)

当使用 java 1.7 编译器

通过 eclipse 进行 maven 全新安装时,我遇到了上述异常

但是如果我将 java 编译器更改为 1.8,它就可以正常工作。但我想在 JBoss 服务器上部署这个 jar,它有 java 1.7 版本。

请帮忙解决这个问题。提前致谢。

您应该在绑定文件中声明您的 icm 前缀。

xmlns:icm="<URI of the icm namespace here>" 添加到根元素。

这与 JAXB 关系不大,而与 XML 关系更大。 JAXB 期望 "qualified name" 为 @xmlType。 "Qualified name" 表示必须定义前缀并指向正确的命名空间。