# Create a SOAP Web Service (using Jersey)

In 
Published 2022-12-03

This tutorial explains to you how to create a simple Java Web Service (JAX-RS) using Jersey implementation on Tomcat. This example is a simple one, just to make you understand the concept of JAX-RS. This example is producing a JSON file for data exchange.

Here are some prerequisites for this article:

  1. You have installed the Apache Tomcat server (v.9)

  2. You have installed Java 8 on your machine

  3. Your environment is Windows (7/8)

  4. You are using Eclipse for creating the JAX-RS

ATTENTION: This JAX-RS RESTful (using Jersey) example will produce JSON for information exchange with the client. You can take a look at the article named "Create a JAX-RS WS using Jersey (producing XML)" as well.

In order to create a RESTful Web Service (JAX-RS) using Jersey you have to create a Dynamic Web Project.

In Eclipse => File => New => Dynamic Web Project

You will see the following screen:

I will name this project "JAX-RS-Jersey-example". Click on "Next".

Click on "Next".

Don't forget to mark "Generate web.xml deployment descriptor". Click on "Finish" and the project will be created for your JAX-RX Web Service.

Now you can convert your Project into a Maven Project.

For this you have to click on the Project name, right click after that (take a look at the picture above) choose Configure and "Convert to Maven Project".

The following screen will appear:

Click on "Finish".

Open the pom.xml file and add the dependencies below:

Now add the following servlet and servlet mapping into the web.xml file.

Now create a class for the JAX-RS.

Right click on the Project name, choose "New", choose Class.

Choose the name of the class and the package name and click on "Finish".

Code the Java class. Here it is an example:

Now you can build the project using Maven:

The goal must be "clean install" to perform a clean build.

Click on "Run".

Click on "Finish".

And now it's time for testing my JAX-RS example (using Jersey).

A JAX-RS (RESTful) Web Service could be tested using a browser:

Here you can see the result of my JAX-RS (RESTful) example (producing JSON) without parameters:

Here you can see the result of my JAX-RS (RESTful) example (producing JSON) with parameters: