jaxbxjcsaxparseexception

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


I am using the below dependencies in my 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 version - 3.1 Java Version - 1.7

Error :

org.xml.sax.SAXParseException; systemId: file:/C:/Data/NewGitRepo/TestICMGitRepo/ICMTrunk/icmarchitecture/src/main/resources/xjb/icmarchitecture/mom/log/binding.xjb; lineNumber: 7; columnNumber: 136; UndeclaredPrefix: Cannot resolve 'icm:Timestamp' as a QName: the prefix 'icm' is not declared. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)

org.xml.sax.SAXParseException; systemId: file:/binding.xjb; lineNumber: 7; columnNumber: 136; cvc-attribute.3: The value 'icm:Timestamp' of attribute 'xmlType' on element 'jxb:javaType' is not valid with respect to its type, 'QName'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)

I am getting the above exception when do maven clean install through eclipse with java 1.7 compiler

But If i change the java compiler to 1.8 its working fine. but i want to deploy this jar in JBoss server which is having the java 1.7 version.

Please help on this. Thanks in Advance.


Solution

  • You should declare your icm prefix in the bindings file.

    Add xmlns:icm="<URI of the icm namespace here>" to the root element.

    This has less to do with JAXB and more with XML. JAXB expects a "qualified name" as @xmlType. "Qualified name" means the prefix must be defined and point to the correct namespace.