Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Monday, July 29, 2013

Hello JAX-RS


In my last post i have given a brief  introduction to JAX-RS. Before look into this further It would be great if we do a hands on session to understand the usage and development procedure.


For the change, I will start with “Hello JAX-RS” instant of “Hello World”!!!!


In order to do this i am using maven as a builder, Tomcat Server as application server and Idea intellij as IDE. Most importantly I am using jersey 1.17.1 as the JAX-RS implementation.


First of all we have to create a web application project. This task can be achieved by maven.


mvn archetype:generate -DgroupId=com.area51.rest -DartifactId=RESTfulExample -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false






After project created by maven, the folder structure looks like. If you see carefully "java" folder is not there in the folder structure.

Folder Structure
Thu i have manually added a folder under src/main/java and ran mvn idea:idea (if you are using eclipse use mvn idea:idea)



I have share the complete project here 


Given pom.xml I have added the  dependency for  jersy and set the source as java 1.6.
HelloJaxRsService.java is the implementation for "Hello JAX - RS"demonstration.

If you carefully study into the code that i have given, you can understand that "@Path("/hello")" annotation indicate the context of the class "HelloJaxRsService.java". "@GET" indicate the methods classify the methods as GET request method (HTTP vocabulary of request operation).  @Path("world/{param}") annotation is a resource in the "hello" context with the parameter.


Okay, Lets up and run this code.

First of all! compile the code using maven!,  get the "war" file! and configure the apache tomacat server with it.

In this example, web request from “projectURL/rest/hello/” will match to “HelloJaxRsService“, via @Path("/hello").

http://localhost:9000/RESTfulExample/rest/hello/world/human request hits the hello context and world resource.


http://localhost:9000/RESTfulExample/rest/hello/home/Vanjikumaran request hits the hello context and home resource.



Monday, April 1, 2013

Create a Web Application project using Maven


This post i will briefly guide you how to create a simple web Application using maven tool.

Since i am using intellij IDEA As IDE, by default the project that i am creating will be created in the "IdeaProjects" directory.

In order to demonstrate this task, i am creating a web app called SampleWebApp.

mvn archetype:create 
-DarchetypeGroupId=org.apache.maven.archetypes 
-DarchetypeArtifactId=maven-archetype-webapp 
-DarchetypeVersion=1.0 
-DgroupId=com.sample.test 
-DartifactId=SampleWebApp 
-Dversion=1.0-SNAPSHOT





As a result of running above given code snippets in the terminal or cmd, you will get bellow directory and file structure. This automated process is reducing the workload of the developer.




Now you can use your IDE to open up the projects and start coding.





for further reading about maven
[1]http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
[2]http://www.sonatype.com/books/mvnref-book/reference/

Installing Maven and Ant in Ubuntu

Configuring Maven or Ant in the Ubuntu is relatively very easy task!

Just a matter of invoking above code code snippets in terminal!

to install Maven

sudo apt-get install maven

for further detail, visit to http://maven.apache.org/


to Install Ant

sudo apt-get install ant

for further detail, visit to http://ant.apache.org/