tumblr counter

CXF wsdl2java Example

CXF wsdl2java Example explains about Generating Java Code From WSDL Document (WSDL) Using CXF wsdl2java Tool.

You can also use this tool for creating client proxy and invoking the web service

I am showing here, an example of generating annotated java code from WSDL document using WSDL To Java tool.

You can also generate server side and client side code using this tool, you can go to below reference

You can see how to generate java codes by following wsdl2java sample

Reference -> http://cxf.apache.org/docs/wsdl-to-java.html

Required Libraries

You need to download

  1. JDK 6
  2. Eclipse 3.7
  3. CXF-2.7.3

Following jar must be in ClassPath

  1. commons-collections-3.2.1.jar
  2. commons-lang-2.6.jar
  3. commons-logging-1.1.1.jar
  4. cxf-2.7.3.jar
  5. httpasyncclient-4.0-beta3.jar
  6. httpclient-4.2.1.jar
  7. httpcore-4.2.2.jar
  8. httpcore-nio-4.2.2.jar
  9. jaxb-impl-2.2.6.jar
  10. jaxb-xjc-2.2.6.jar
  11. neethi-3.0.2.jar
  12. velocity-1.7.jar
  13. wsdl4j-1.6.2.jar
  14. xmlschema-core-2.0.3.jar
Note

For generating WSDL you can either deploy CXF Web Service Tutorial or you can copy WSDL and Schema files from CXF java2wsdl Example

If you gone for first option, then you can directly provide WSDL "http://localhost:8080/CXFTutorial/ChangeStudent?wsdl", if you are opted for second, ie; copying WSDL & Schema then you need to add this WSDL & Schema on root folder of the project as ChangeStudent.wsdl

We are going through the second approach ie; copying WSDL & Schema (see the project structure)

please see the below project structure

wsdl2java Example

CXF WSDLToJava Tool

I am going to call WSDLToJava class from main method, you can also invoke WSDLToJava from command line too.

Here I am providing option "-d" which specifies the where the files need to be generated (In this example, it is generated inside src).

package com.tool;

import org.apache.cxf.tools.wsdlto.WSDLToJava;

// CXF wsdl2java Example
public class WSDLToJavaCodeGenerator {
 
public static void main(String[] args) {
   
try {
     
// you can also specify WSDL directly like http://localhost:8080/CXFTutorial/ChangeStudent?wsdl
     
WSDLToJava.main(new String[] { "-d", "src", "ChangeStudent.wsdl" });
      System.out.println
("finished %%%%%%%%%%");
   
} catch (Exception e) {
     
e.printStackTrace();
   
}

  }

}

After running the above main class, you can see the generated java code (selected package) on following screenshot

wsdl2java Example












CXF wsdl2java Example wsdl2java sample WSDL To Java tool How To Generate Java Code From WSDL Document Using CXF CXF wsdl2java Using Eclipse CXF wsdl2java Client

You might also like following tutorials :

Java Tutorial Apache CXF Tutorial Hibernate Tutorial Spring Tutorial Struts Tutorial
6 Comments on "CXF wsdl2java Example"
21.08.2013 09:57:53 alkiviadis
You are awsome. Thnx a bunch for this. Where did you find the jars needed for this to work? I mean how did you find which ones where necessary for wsdl2java class from all the other?
21.08.2013 10:26:02 alkiviadis
My friend you've made my day. Thank you again. I'm using cxf 2.7.6 . To make it work I had to add two more jars. stax2-api-3.1.1.jar and woodstox-core-asl-4.2.0.jar. They can be found in the lib folder.
22.08.2013 08:48:26 admin
@alkiviadis,

Thanks alkiviadis, I appreciate your comment.
23.08.2013 06:54:07 alkiviadis
Hello again. Since this article was so helpful for me, I'll take the chance of asking something more. When the client is generated by cxf as a plugin (eclipse) there is an option of testing the client through the eclipse interface. Do you know how does cxf exposes those methods dynamically? How does it constructs the parameters when they are not simple POJOs? What I want to do it do the exact same thing, but through a browser. If this question is completely irrelevant with this article, please contact me through my email, if you have any suggestions that would help me. Thank you very much once again.
03.01.2014 04:17:55 Redmond
hi admin, can u show the first option
12.01.2014 22:32:53
@Redmond,

I have already wrote articles about generating client directly from wsdl some time ago,

1. http://www.javatips.net/blog/2012/09/java-wsimport-tool-example ( Using JDK wsimport tool )
2. http://www.javatips.net/blog/2011/09/create-cxf-client  ( Using CXF way )