Java Login


Hello guys, is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.

     << Previous
Next >>     

Rest First Application

In this tutorial, We will discuss how to create simple restful Web-service. Let us start writing actual RESTful web services with Jersey Framework step-by-step. I am using Eclipse-kepler for creating restful webservice. The first step is to create a Dynamic Web Project using Eclipse IDE. Follow the option File -> New -> Maven Project -> click Next button. You will see below window.

In window, type jersey in Filter text box and find highlighted option in above window. If this option is not available in list, it means you have not register this option with eclipse. For regiter this option, click on Add ArchType and fill details as per below window.

Now select org.glassfish.jersey.archetypes and click on Next Button.

Once your project is created successfully, you will have following directory structure in your Project Explorer:

<project xmlns="" xmlns:xsi=""





<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
<!-- this to get JSON support -->

you create a file called web.xml in the WebContent\WEB-INF folder as the following:

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "" >

<display-name>Archetype Created Web Application</display-name>
<servlet-name>Jersey Web Application </servlet-name>
jersey.config.server.provider.packages </param-name>
<param-value> </param-value>
<load-on-startup>1 </load-on-startup>

<servlet-name>Jersey Web Application </servlet-name>
<url-pattern>/webapi/* </url-pattern>


In web.xml, I am using org.glassfish.jersey.servlet.ServletContainer servlet for configure restful webservice. I have configure package for searching all annotations and create a one instance when application start using load-on-startup. In this example /webapi/* pattern use for restful URL.


public class FirstRestWebService {

public String getFirstMessage(){
return "This is my first Web RestService";


Run Program

Make a request to get a result from restful webservices. PUT http://localhost:8080/FirstRestWebService/webapi/firstMessage on browser and see the below result. In this example, I have created only one class and I have mentioned @Path annotation on this class. This is sufficient for creating restful webservice. I used @GET annotation for creating get request.

     << Previous
Next >>