I have a Maven project where i need to generate java classes from multiple wsdl files.
I have analysed using maven plugins axistools-maven-plugin
and cxf-codegen-plugin
but the problem i am facing are is that Java files from different wsdl's should go to different packages.
I have checked this link : http://decimalsolutions.blogspot.in/2011/10/wsdl2java-maven2.html but it doesn't solve my problem.
How to achieve this?
The documentation states you can use the <extraarg>
element to pass in parameters to the wdsl to java process. So, you can configure your cxf-codegen-plugin
in the following manner
<configuration>
<sourceRoot>${project.build.directory}/generated-code/mywebservice</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/serviceOne.wsdl</wsdl>
<extraargs>
<extraarg>-p</extraarg>
<extraarg>first.packagename</extraarg>
</extraargs>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/serviceTwo.wsdl</wsdl>
<extraargs>
<extraarg>-p</extraarg>
<extraarg>another.packagename</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
With a jaxb binding file, you can change the package (see this documentation).
If you're using maven and the cxf plugin, you can add this to your pom.xml:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl><path_to_wsdl</wsdl>
<frontEnd>jaxws21</frontEnd>
<faultSerialVersionUID>1</faultSerialVersionUID>
<bindingFiles>
<bindingFile>src/main/resources/binding.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-fluent-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
</dependencies>
</plugin>
Have you looked at XJC bindings, there are some notes on the Oracle site and if you are happy with the CXF plugin you can pass a separate bindings file for each WSDL using the code you can see in example one on the plugin's site.
An example fragment from the plugin configuration:
...
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/first.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/first.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/second.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/second.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
...
Where first.xjb would contain:
<jaxws:bindings wsdlLocation="path/to//serviceOne.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
...
</jxb:globalBindings>
<jxb:schemaBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<jxb:package name="your.first.package"/>
</jxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
Now you can configure all manner of translations and mappings.
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