Java, Software Development

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 the wsimport command. 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 to process WSDL files

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.

Generated classes from WSDL files using cxf-codegen-plugin

The following are the other classes.

Generated classes from WSDL files using cxf-codegen-plugin

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

Aide from the cxf-codegen-plugin to process WSDL files, we use another plugin (in the same pom.xml) that 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 on GitHub.

Loading

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

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.