Java, Software Development

Generate Java classes from WSDL files using cxf-codegen-plugin

There are many ways to generate Java classes from WSDL files – one of them is using the cxf-codegen-plugin, which comes from the Apache Maven CXF. Note that this post will not work with the JDK version beyond 1.8. (See comments section). However, it may still be useful for legacy applications.

Software Requirements

We used the following items for this post.

  • SOAP 1.2
  • Java 8
  • Windows 10
  • Apache Maven
  • IntelliJ IDEA 2021.1
  • cxf-xjc-runtime from Apache CXF (See pom.xml)

WSDL File To Generate Java Classes

We will use a WSDL file downloaded from the following URL. Head to the URL and then save the content to a file.

http://www.webservicex.net/geoipservice.asmx?WSDL

The web service may change anytime without us knowing it unless we consume it. Therefore, we included the WSDL file in our Maven project. NOTE: the following URL is no longer available, but we can use other SOAP-based web services. They may be running on our local machine or hosted somewhere on the Internet.

Non-Standing SOAP 1.2 Binding

We may encounter an issue similar to the following problem with wsimport. It may still work with an older SOAP version, but we haven’t tried it. If possible, please use wsdl2java directly or via the cxf-codegen-plugin.

We will only deal with SOAP 1.2 in this post.

Add the cxf-codegen-plugin Maven plugin.

Next, we update our pom.xml, as shown below.

Then, we add the following dependency.

When we do a clean install, we get the following generated classes and the jar file.

 

Check Java classes Created From WSDL via cxf-codegen-plugin in the jar file

Another plugin (in the same pom.xml) is responsible for moving the generated compiled classes to our jar file.

Lastly, update the pom.xml to include the following snippet. The plug-in adds all generated classes into the final application jar file.

Download The cxf-codegen-plugin Sample Codes

The files are available at the following link.

https://github.com/Turreta/Generate-Java-classes-from-WSDL-files-using-cxf-codegen-plugin-in-Maven

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like