SOAP Fault handling using Exception in JAX-WS webservice

This tutorial will show you how we can generate SOAP fault error code and message using Exception handling in SOAP based JAX-WS webservice. For this tutorial we will create a standalone project in Eclipse.

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
Have maven installed and configured
JAX-WS 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 : soapws

Step 2. Modify the pom.xml file as shown below.

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. Create below service endpoint interface

Step 5. Create below service implementation class

Step 6. Create below POJO class

Step 7. Create below class for handling SOAP fault error code and error message

Step 8. Create below custom Exception class for handling fault error code and error message using Exception

Step 9. Now build the project by executing below command from command prompt. Navigate to the project root directory and execute the below command

If you see BUILD SUCCESSFUL message after executing above command then refresh the project in Eclipse, you will see  below few classes have been generated under the package

SOAP Fault handling using Exception

The generated xsd is below under WEB-INF/wsdl

The generated wsdl file is below under WEB-INF/wsdl

Step 10. Create a webservice publisher class which will publish the webservice

Step 11. Create below client class to consume the service

Step 12. Now run first publisher class then run client class, you will see below output

Now replace


you will get similar output like below

Thanks for reading.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.