JAXB - The Value property is already defined. Use <jaxb: property> to resolve this conflict.
Using JAXB to create XML binding classes.
The schema is based on a set of obsolete XML files and includes this fragment:
<xs:complexType name="MetaType"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute type="xs:string" name="Name" /> <xs:attribute type="xs:string" name="Scheme" /> <xs:attribute type="xs:string" name="Value" /> </xs:extension> </xs:simpleContent> </xs:complexType> The "Value" attribute conflicts with the "value" property xs:string , and code generation is generated with an error:
com.sun.istack.SAXParseException2: Property "Value" is already defined. Use <jaxb:property> to resolve this conflict. The answer is to use JAXB bindings ( site-template.xjb ):
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"> <bindings schemaLocation="site-template.xsd" version="1.0"> <!-- Customise the package name --> <schemaBindings> <package name="com.example.schema"/> </schemaBindings> <!-- rename the value element --> <bindings node="//xs:complexType[@name='MetaType']"> <bindings node=".//xs:attribute[@name='Value']"> <property name="ValueAttribute"/> </bindings> </bindings> </bindings> </bindings> Nodes are found and renamed in XPath expressions, avoiding name conflicts.
Using this XML binding file, the generated Java class ends up with the desired getValueAttribute() (as well as getValue() ).
If you want to avoid creating / modifying a JAXB binding file, and you do not mind annotating your XSD, you can add the jxb: property annotation to your attribute definition, for example:
<xs:complexType name="MetaType"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute type="xs:string" name="Name" /> <xs:attribute type="xs:string" name="Scheme" /> <xs:attribute type="xs:string" name="Value"> <!-- rename property generated by JAXB (avoiding "Value" name conflict) --> <xs:annotation> <xs:appinfo> <jxb:property name="valueAttribute"/> </xs:appinfo> </xs:annotation> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> with suitable additions to the xs: schema tag:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"> After creating the xxxx.xjb file for the duplicate attribute name βvalueβ (default duplicate βvalueβ provided by JAXB), as shown below, run the XJC command to create the JAXB objects
xjc -p "com.track.doc" -d "C: \ JAXBDocuments \ prasam \ Desktop \ JAXB_me \ DealerTrace" appSamp.xsd -b xxxx.xjb
appSmp.xsd : -
<xsd:complexType name="range"> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="value" type="xsd:string"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> xxxx.xjb : -
<?xml version="1.0" encoding="UTF-8"?> <bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"> <bindings schemaLocation="appSmp.xsd" version="1.0"> <schemaBindings> <package name="com.track.doc"/> </schemaBindings> <bindings node="//xs:complexType[@name='range']"> <bindings node=".//xs:attribute[@name='value']"> <property name="valueAttribute"/> </bindings> </bindings> </bindings> </bindings> I had a problem using a solution with Eclipse (for both Helios SR1 and Juno SR1) and CXF 2.6.3. The solution was similar to what Kitesu was saying. Namely, the New> Web Service wizard from Eclipse copies wsdl to the file folder WebContent / wsdl. I had to put wsdl and a binding file there. Otherwise, the binding file gave the error "is not part of this compilation."
I was not able to use the built-in WSDL scheme, but it worked with an external scheme, as in answer # 1.
I am using the CXF servlet endpoint configuration parameter. In my WSDL, I have:
<wsdl:port binding="axis2:ConverterSOAP12Binding" name="ConverterSOAP12port_http"> <soap12:address location="http://localhost/Converter/services/Converter"/> </wsdl:port> The wizard generated this in my web.xml, which works fine:
<servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> But he puts this in cxf-servlet.xml:
<jaxws:endpoint xmlns:tns="http://wtp" id="converterporttype" implementor="wtp.ConverterPortTypeImpl" wsdlLocation="wsdl/Converter.wsdl" endpointName="tns:ConverterSOAP12port_http" serviceName="tns:Converter" address="/ConverterSOAP12port_http"> <jaxws:features> <bean class="org.apache.cxf.feature.LoggingFeature" /> </jaxws:features> </jaxws:endpoint> I had to change the address to the full URL, for example:
address="http://localhost:8080/Converter/services/Converter"> This binding file mentioned in another answer does not work for me with CXF 3.0.0. Note that the jaxb namespace has a "binding" element as well as the jaxws namespace, so we need to declare them:
<?xml version="1.0" encoding="UTF-8"?> <bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://java.sun.com/xml/ns/jaxws" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" wsdlLocation="mesh.wsdl" > <bindings node="wsdl:definitions/wsdl:types/xs:schema[..."> <jaxb:bindings node="./xs:element[@name='Profiles']"> <jaxb:property name="ProfilesElement"/> </jaxb:bindings> </bindings> </bindings> In my case, the schema was already inside the WSDL, so I did not need to specify the schemaLocation attribute.