I'm trying to generate a client with maven and jaxb from a wsdl file with 2 schemas inside and some elements with the same name from different schemas
When I try to execute the compilation I'm getting the next error:
Two declarations cause a collision in the ObjectFactory class.
WSDL schemas:
<wsdl:types>
<schema targetNamespace="http://ws.services" xmlns="http://www.w3.org/2001/XMLSchema">...</schema>
<schema targetNamespace="http://ws.models" xmlns="http://www.w3.org/2001/XMLSchema">...</schema>
</wsdl:types>
I tried renaming the elements that produce the error, but then my spring client receive the correct SOAP message, but it doesn't populate the response object properly (all its attributes are null). I guess the problem might come from renaming the response classes, so that's why I'm trying to generate different packages keeping the original name of all the classes.
In order to do that, I wrote the next bindings file but I don't know what I'm doing wrong that it is not working.
bindings.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<jaxb:bindings schemaLocation="mywsdl.wsdl#types?schema1"
node="/xs:schema[@targetNamespace='http://ws.services']">
<jaxb:schemaBindings>
<jaxb:package name="package1" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="mywsdl.wsdl#types?schema2"
node="/xs:schema[@targetNamespace='http://ws.models']">
<jaxb:schemaBindings>
<jaxb:package name="package2" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
My configuration part in the maven file is the next, just in case it is useful:
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlLocation>wsdl/mywsdl.wsdl</wsdlLocation>
<wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>mywsdl.wsdl</wsdlFile>
</wsdlFiles>
<bindingDirectory>src/main/resources/wsdl</bindingDirectory>
<bindingFiles>
<bindingFile>bindings.xml</bindingFile>
</bindingFiles>
<packageName>original.package</packageName>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
</configuration>
When I compile with this bindings files, the same error appears. So I think that maybe it isn't right.
Do you find any mistakes?
Thanks.
The wsimport command-line tool processes an existing Web Services Description Language (WSDL) file and generates the required artifacts for developing Java™ API for XML-Based Web Services (JAX-WS) web service applications.
JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances. JAXB technology consists of a runtime API and accompanying tools that simplify access to XML documents.
Generally we create a bindings file with . xjb extension to resolve any conflicts in the WSDL or schema. For example if two elements have the same name and you want to distinguish between them you can rename one by specifying it the bindings file.
From my experience it is best to create 2 binding files (one for each WSDL file). Update your pom.xml accordingly and make sure that the root element of the binding files is jaxws:bindings (and not jaxb:bindings!)
Some hints:
Example binding file for "package1":
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
wsdlLocation="mywsdl.wsdl"
version="2.0">
<jaxws:package name="package1"/>
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
<jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping>
<jaxws:bindings node="//wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://ws.services']">
<jaxb:schemaBindings>
<jaxb:package name="package1"/>
</jaxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With