CXF Tutorial With Apache Maven

In this tutorial, we are implementing a jax-ws web service using Apache CXF with Maven and deployed in Tomcat.

Apache CXF is a free and open source project, and a fully featured Web service framework. It helps you building web services using different front-end API's, like as JAX-RS and JAX-WS.

Services will talk different protocols such as SOAP, RESTful HTTP, CORBA & XML/HTTP and work with different transports like JMS, HTTP or JBI.


You need to have following dependencies

<?xml version="1.0" encoding="UTF-8"?>



	<name>cxftutorial Maven Webapp</name>




Create a Student Object

package com.student;

public class Student {
  private String name;
  public String getName() {
    return name;
  public void setName(String name) { = name;

Create a Service Interface

This service interface will defines which methods of web service, to be invoked by the client

package com.student;

import javax.jws.WebService;

public interface ChangeStudentDetails {
  Student changeName(Student student);

Implement the Service Interface

Here we implement the service interface created on the previous step

package com.student;

import javax.jws.WebService;

@WebService(endpointInterface = "com.student.ChangeStudentDetails")
public class ChangeStudentDetailsImpl implements ChangeStudentDetails {
    public Student changeName(Student student) {
      student.setName("Hello "+student.getName());
      return student;

Create a cxf.xml

CXF is using Spring internally, Finding classes by spring we need to add service implementation class on "jaxws:endpoint" tag

<beans xmlns=""
    xmlns:xsi="" xmlns:jaxws=""

    <jaxws:endpoint id="changeStudent"
        implementor="com.student.ChangeStudentDetailsImpl" address="/ChangeStudent" />



Modify web.xml file to find CXF servlet and cxf.xml

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

  <display-name>Archetype Created Web Application</display-name>




Publishing CXF Web Service

Deployed CXF Web Service

CXF WebService Running


you can also see CXF client example in order to run this service

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