Java, Software Development

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

java Sort Enum Properties Monitor Directory File Lambda Expression parameter return types Validate XML String XSD ExecutorService AutoCloseable Try-With-Resources Convert LocalDateTime OffsetDateTime Run Codes Before Shutdown XML Tag Lambda PostgreSQL JDBC invoke JavaScript Applet SFTP Batch hang block main thread MySQL JDBC try-with-resources delete Unencrypted SoapFault Apache CXF Remove XML Element XSLT skip execute finally public static void main constructor fields Eclipse convert Iterator Stream StreamSupport XMLEncoder XMLDecoder rename P6Spy JDBC Example PDF Version JasperReports Run from Ant iReport Page Numbers Count entities persistence context hibernate

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 version of SOAP, 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 along with the jar file.

 

 

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

There is another plugin (in the same pom.xml) 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? Please visit our Facebook page!

You Might Also Like

2 Comments

  1. 1

    Hi Karl,
    Thanks for the informative post. I just have one question.
    where do you get the binding.xml file from, that is included in the pom configuration.
    src/main/resources/binding.xml ???
    Thanks,

  2. 2

    NOTE: This won’t compile with JDK 9, 11, and 14. Most probably, it won’t work with JDK 10, 12, 13, 15, and later.

Comments are closed.