I’m trying to generate Java classes from a WSDL file using the Maven plugin com.sun.xml.ws:jaxws-maven-plugin. The WSDL includes embedded XSD schema(s), and I’m not allowed to modify the WSDL or its schemas.
My goal is to add the @XmlRootElement annotation to the generated classes ImportStatusReadRequest and ImportStatusReadResponse using an external jaxb-bindings.xml file.
Unfortunately, I cannot manage to properly target the relevant node using XPath in the bindings file. Every attempt leads to the following error during the jaxws:wsimport execution:
[ERROR] XPath evaluation of "<node>" results in an empty target node
Here’s what I have tried:
- Using
<xjc:simple />globally, which does generate the@XmlRootElementannotation - However, this also enables automatic pluralization for List properties (e.g., a
List<ITEM>property is nameditemsinstead ofitem), which I want to avoid.
So, my needs are:
- To target only the specific types in the embedded schema using XPath
- To add the
@XmlRootElementannotation without enabling pluralization
I will include:
- The plugin configuration
- A simplified version of the WSDL file (representative of the structure)
- My current jaxb-bindings.xml
Any guidance would be greatly appreciated — thank you!
<!-- pom.xml -->
<plugin>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>4.0.3</version>
<configuration>
<sourceDestDir>${project.basedir}/target/generated-sources</sourceDestDir>
<destDir>${project.basedir}/target/generated-sources</destDir>
<wsdlDirectory>${project.basedir}/src/main/resources/wsdl</wsdlDirectory>
<bindingDirectory>${project.basedir}/src/main/resources/wsdl</bindingDirectory>
</configuration>
<executions>
<execution>
<id>default</id>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- SST-073.wsdl -->
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="os_ImportStatusRead" targetNamespace="urn:be.ch:KTBE_ERP_FI:IMPORT_STATUS" xmlns:p1="urn:be.ch:KTBE_ERP_FI:IMPORT_STATUS" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsdl:documentation/>
<wsp:UsingPolicy wsdl:required="true"/>
<wsp:Policy wsu:Id="OP_os_ImportStatusRead"/>
<wsdl:types>
<xsd:schema targetNamespace="urn:be.ch:KTBE_ERP_FI:IMPORT_STATUS"
xmlns="urn:be.ch:KTBE_ERP_FI:IMPORT_STATUS"
xmlns:p5="urn:be.ch:KTBE_ERP_FI:GENERAL"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="urn:be.ch:KTBE_ERP_FI:GENERAL"/>
<xsd:element name="ImportStatusRead_Response" type="ImportStatusRead_Response"/>
<xsd:element name="ImportStatusRead_Request" type="ImportStatusRead_Request"/>
<xsd:complexType name="ImportStatusRead_Response">
<!-- complexType definition -->
</xsd:complexType>
<xsd:complexType name="ImportStatusRead_Request">
<!-- complexType definition -->
</xsd:complexType>
</xsd:schema>
<xsd:schema targetNamespace="urn:be.ch:KTBE_ERP_FI:GENERAL"
xmlns="urn:be.ch:KTBE_ERP_FI:GENERAL"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="SenderParms">
<!-- complexType definition -->
</xsd:complexType>
<xsd:complexType name="ReturnCodeID">
<!-- complexType definition -->
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<!-- wsdl:message and wsdl:service -->
</wsdl:definitions>
<!-- jaxws-bindings.xml -->
<jaxws:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="https://jakarta.ee/xml/ns/jaxws"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="3.0">
<jaxws:bindings wsdlLocation="SST-073.wsdl"
node="wsdl:definitions/wsdl:types">
<!-- This adds @XmlRootElement annotation, but enable pluralisation -->
<jaxws:bindings node="xs:schema">
<jaxb:globalBindings>
<xjc:simple/>
</jaxb:globalBindings>
</jaxws:bindings>
<!-- This fails to target the node -->
<jaxws:bindings node="/xs:schema[@targetNamespace='urn:be.ch:KTBE_ERP_FI:IMPORT_STATUS']">
</jaxws:bindings>
</jaxws:bindings>
</jaxws:bindings>