java2db

Java RESTful web service example in maven using JAX-RS



Maven Maven (Tool from Apache) is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

Basic Requirements  to develop Java RESTful web service example in maven :

 

Softwares :
Java (Download).
GlassFish server (Download).
Eclipse IDE (Download).

 

Java RESTful web service example in maven using JAX-RSUse all advance versions of  java ,Eclipse and  GlassFish.

 Steps to develop Java RESTful web service example in maven :

  Step 1 :

Create a Maven Project in Eclipse IDE

(File – new – Other – Maven – MavenProject)

 

 

Java RESTful web service example in maven using JAX-RS Step 2 :

Click Next (Keep defaults).
Java RESTful web service example in maven using JAX-RS

 

 

 Step 3 :

Select Archetype
Java RESTful web service example in maven using JAX-RS

 

 

Java RESTful web service example in maven using JAX-RS Step 4 :

If not found the above Archetype  , Click Add  Archetype  button and enter details like below.

(Use advance version for Archetype Version ).

click OK button ,select the added Archetype .

 

 

 Step 5 :

Enter Group Id (package name) , Artifact Id (Project name) and click finish button.
Java RESTful web service example in maven using JAX-RS

It will take few minutes to create a maven project .

 

 

 Step 6 :

The complete directory structure as follows .

create a servletAdd servlet-api-2.x.jar to the Libraries to clear the project errors.

 


All the below sample source files generated automatically .

 

 index.jsp

 

 MyResource .java

 

 web.xml

 

 

 Step 7 :

Deploy the Maven project in any web/Application server (GlassFish,Tomcat,WebSphere,Jboss,Wildfly).

 

 

 Step 8 :

Enter the below URL in any web browser address bar. (Change port 9090 to your server port) . Click enter. The below response will come to the client window.

Click the Jersey resource  link to call the RESTful web service.

 

 step 9 :

Finally we will get the response from RESTful web service as follows.

From the above (screen) response URI ,

http://localhost :9090/maven-RESTfulWebServiceExample/webapi/myresource  (configured in the index.jsp file)

localhost : Is the IP address (127.0.01).

9090 : Is the server port.

maven-RESTfulWebServiceExample : Project name (Web application name).

webapi :  Is the <url-pattern>  that configured in the web.xml file .

myresource : Is the resource path that configured in the MyResource .java class (@Path(“myresource”)).

 




Related Posts :
How to Connect to Oracle from Liferay portlet ( Java Liferay and Oracle integration )
How to Connect Liferay 7 to PostgreSQL ( Java Liferay portlet and PostgreSQL integration )
How to call C# .Net WCF web service in java SOAP client ( Visual Studio 2013 )
How to call PHP RESTful web service in java client
How to call java SOAP web service in php ( php web service client )
Solution to SSLHandshakeException (skip the certificate for Java and LDAP bind)
How to create a java client to call RESTful web service JAX-RS (Jersey )
Example java RESTful web service for xml response (JAX-RS , Jersey)
   [will not be published]



^ <