By Marone: December 2017 | last update: December 2019

Jersey REST API deployed on Tomcat

Goal

In this article i will show you how to develop a JAX-RS RESTful web service. It uses the reference implementation Jersey and runs on tomcat. This article based on classes from Rest with jersey

Used technologies

JDK 1.8
Maven 3.2
Tomcat 8
Eclipse IDE (Luna)
Maven dependencies: jersey 1.19.4

create maven project in eclipse

maven atype

pom.xml

Please change the pom file, the dependencies part should look like this

Set target runtime

For the first time you have to set the project targeted runtime (Tomcat), see the below image:

project target runtime

Copy classes from previous arcticle

At first add a new package com.wstutorial.rest and copy the following classes from here
TestData.java
Tutorial.java
TutorialResource.java

In case if "src/main/java" does not exist
The "maven-archetype-webapp" is not creating "src/main/java" source folder by default, in this case you can add a new folder After this right-click on your project and then click Maven -> Update Project ...

Change web.xml

Run the application

right-click on your project, Run AS -> Run on Server, then select "Tomcat ...at Localhost" and click "finish"

Using curl



References