Javatpoint Logo
Javatpoint Logo

JAX-RS Example Jersey

We can create JAX-RS example by jersey implementation. To do so, you need to load jersey jar files or use maven framework.

In this example, we are using jersey jar files for using jersey example for JAX-RS.


Click me to download jersey jar files.

There are created 4 files for hello world JAX-RS example:

  1. Hello.java
  2. web.xml
  3. index.html
  4. HelloWorldClient.java

The first 3 files are created for server side and 1 application for client side.


JAX-RS Server Code

File: Hello.java

File: web.xml

File: index.html

Now run this application on server. Here we are using Tomcat server on port 4444. The project name is restfuljersey.

After running the project, you will see the following output:

jax rs example using jersey output

JAX-RS Client Code

The ClientTest.java file is created inside the server application. But you can run client code by other application also by having service interface and jersey jar file.

File: ClientTest.java

Output:

Hello Jersey Plain
<?xml version="1.0"?><hello> Hello Jersey</hello>
<html> <title>Hello Jersey</title><body><h1>Hello Jersey HTML</h1></body></html> 

Click me to download JAX-RS example using eclipse without jersey jar files.




Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA