This tutorial will show you how we can consume SOAP based webservice using Apache cxf, Spring and Maven. For this tutorial we will create one maven standalone project in Eclipse. Please go through the tutorial first

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse.


The following configurations are required in order to run the application
Eclipse Kepler
JDK 1.8(if you use jdk 1.7 then use Tomcat 7)
Tomcat 8
Have maven installed and configured
Apache cxf and Spring dependencies in pom.xml
Now we will see the below steps how to create a maven based spring project in Eclipse
First we will create service project
Step 1. Create a maven based web project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.

Now enter the required fields (Group Id, Artifact Id) as shown below
Group Id : com.roytuts
Artifact Id : cxf-spring-client
Step 2. Modify the pom.xml file as shown below.

<project xmlns="" xmlns:xsi=""
            <!-- maven compiler plugin definition -->
            <!-- Generate Java classes from WSDL during build -->
                            <!-- which source folder the generated classes should be placed in a package -->
                                    <!-- put the wsdl file in this location -->
            <!-- Add generated sources - avoids having to copy generated sources to
                build location -->
            <!-- Build the JAR with dependencies -->

Step 3. If you see JRE System Library[J2SE-1.5] then change the version by below process

Do right-click on the project and go to Build -> Configure build path, under Libraries tab click on JRE System Library[J2SE-1.5], click on Edit button and select the appropriate jdk 1.8 from the next window. Click on Finish then Ok.

Step 4. Now go to the project directory from command prompt and execute the command “mvn clean compile install” to generate the client or stub from wsdl file. You will see the following classes have been generated under src/main/java in com.roytuts.service package


Step 5. Now create a Java main class to test the client. Please make sure your server project ( is running

package com.roytuts.client;
import com.roytuts.service.Product;
import com.roytuts.service.ProductService;
import com.roytuts.service.ProductServiceService;
public class ProductClient {
    public static void main(String[] args) {
        try {
            ProductServiceService productServiceSvc = new ProductServiceService();
            ProductService productService = productServiceSvc.getProductServicePort();
            Product product = productService.getProduct(101);
        } catch (Exception e) {

Step 6. Now run the main class, you will see below output in the console

Feb 10, 2016 7:49:14 AM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {}ProductServiceService from WSDL: file:/D:/marsworkspace/cxf-spring-client/src/main/resources/wsdl/ProductService.wsdl

Please read server project ( then read client project.
Thanks for reading.


Leave a Reply

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