Wednesday, 7 August 2013

JAX-WS Web services using Apache CXF

In this example we are using Apache CXF for JAX-WS implementation , see more about Apache CXF

Software Used

  1. Eclipse Kepler Release
  2. Tomcat 6
  3. Java 1.6
  4. CXF 2.7.6

Environment Setup

1. Download apache CXF from
2. Extract CXF zip file
3. Setup CXF run time in eclipse
Go to Eclipse Window->Preference->Web services and select CXF run time

Create Web Service

1. Create a Dynamic web project in eclipse and choose Tomcat 6 as Target run time
2. Create a java class to implement Web service method
package com.pretech;

public class MyWebService {

    public String giveWelcome(String name) {
        return "Welcome " + name;

3. Right click on the dynamic web project and create a new web service
4. Click on next button and we can see the below window
1.Select web service implementation class (MyWebService)
2.Slider should be in Start Service point
3.Service Runtime should be Tomcat 6
4.Web service run time should be Apache CXF
5.Service project should be this project
6.Check Publish the Web service option
5. Click on next and start the server and click on finish .That's all Web service implementation is done now we can see the generated wsdl file.

Test Web Service

1. Go to Eclipse run-> and Launch Web services Explorer
2. Click on WSDL page and enter the WSDL url (Open MyWebService.wsdl file and get the wsdlsoap:address and append ?wsdl) example :http://localhost:8080/JAX-WS-CXF/services/MyWebService?wsdl


3. Click on go button and we can see the web service methods over there in the next screen. Select giveWelcome method and test it.