CXF java2wsdl Example

CXF JavaToWS Tutorial explains about generating WSDL And Other Artifacts From Web Service Endpoint's Implementation (SEI) Using CXF JavaToWS Tool

I am showing here, an example of generating WSDL,XSD schema using CXF JavaToWS Tool.

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

Reference ->

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

You can copy the implementation class and other domain objects from CXF Web Service Tutorial

(please see the below project structure screenshot)

CXF java2wsdl Example

JavaToWS Tutorial

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

Here I am providing option "-o" which specifies the name of the generated WSDL file, "-createxsdimports" specifying that seperated XSD will be generated and imported inside WSDL, if you are not specified this, complex types will be inlining them into the WSDL. And finally "-wsdl" which specifies to generate the WSDL file.

package com.tool;


//CXF java2wsdl Example
public class JavaToWSCodeGenerator {
public static void main(String[] args) {
try {
JavaToWS.main(new String[] { "-d", "src", "-o", "ChangeStudent.wsdl", "-createxsdimports", "-wsdl",
"com.student.ChangeStudentDetailsImpl" });
("finished %%%%%%%%%%");
} catch (Exception e) {



After running the above main class, you can see the generated WSDL and XSD schema on following screenshot

CXF java2wsdl Example

You can see the source of generated WSDL and XSD schema files below


<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ChangeStudentDetailsImplService"
	targetNamespace="" xmlns:wsdl=""
	xmlns:tns="" xmlns:xsd=""
		<schema xmlns="">
			<import namespace="" schemaLocation="ChangeStudent_schema1.xsd" />
	<wsdl:message name="changeName">
		<wsdl:part name="parameters" element="tns:changeName">
	<wsdl:message name="changeNameResponse">
		<wsdl:part name="parameters" element="tns:changeNameResponse">
	<wsdl:portType name="ChangeStudentDetails">
		<wsdl:operation name="changeName">
			<wsdl:input name="changeName" message="tns:changeName">
			<wsdl:output name="changeNameResponse" message="tns:changeNameResponse">
	<wsdl:binding name="ChangeStudentDetailsImplServiceSoapBinding"
		<soap:binding style="document" transport="" />
		<wsdl:operation name="changeName">
			<soap:operation soapAction="" style="document" />
			<wsdl:input name="changeName">
				<soap:body use="literal" />
			<wsdl:output name="changeNameResponse">
				<soap:body use="literal" />
	<wsdl:service name="ChangeStudentDetailsImplService">
		<wsdl:port name="ChangeStudentDetailsImplPort" binding="tns:ChangeStudentDetailsImplServiceSoapBinding">
			<soap:address location="http://localhost:9090/ChangeStudentDetailsImplPort" />


<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="" xmlns:xs=""
	attributeFormDefault="unqualified" elementFormDefault="unqualified"
	<xs:complexType name="student">
			<xs:element minOccurs="0" name="name" type="xs:string" />
	<xs:element name="changeName" type="changeName" />
	<xs:complexType name="changeName">
			<xs:element minOccurs="0" name="arg0" type="student" />
	<xs:element name="changeNameResponse" type="changeNameResponse" />
	<xs:complexType name="changeNameResponse">
			<xs:element minOccurs="0" name="return" type="student" />


Your email address will not be published. Required fields are marked *