Today we will talk about building a Restful project using maven and jersey libraries. For this to be possible maven archetype, a tool to build projects out of templates, will be used.
In this tutorial we will be using command line maven, you can download and follow the installation intructions on http://maven.apache.org/download.cgi.
After installation follow the steps below:
1 - Go to your workspace and type:
mvn archetype:generate -DarchetypeCatalog=http://download.java.net/maven/2
2 - Archetypes will be downloaded from the catalog. After downloading you'll see this message "Choose a number or apply a filter", type 3.
3 - After selecting rest archetype, you will fill the project configuration information according to the example below:
groupId - br.com.restful (Identifies your project uniquely between all your projects)
artifactId - blog-restful-webapp (Represents the war name without version)
version - 1.0 (Identifies the project version)
package - br.com.restful (Represent the package structure)
4 - Next, a confirmation message will show up, just type Y and your project will be created.
5 - After the project have been created, type:
cd PROJECT_NAME mvn clean install (Clean and build)
6 - The result of previous step should be BUILD SUCCESS, which means that now you already have your rest project fully configured, compiling and ready to be executed.
After doing all these steps you will have import the project into your IDE. In this example eclipse will take place, but be free to use your prefered IDE since maven is IDE agnostic.
Open eclipse and click with the mouse right button on Project Explorer -> Import -> Existing Maven Projects, select your project and click Finish.

Now you can take a look on the class created by the template in br.com.restful.MyResource.
Next, click on the mouse right button over the project and run on your server. In this example we used Tomcat 6.
A page like this should appear.
To access the GET method you just have to access the link:
http://localhost:8080/blog-restful-webapp/webresources/myresource, remember that port should be set accordingly to the server configuration. On this case we used tomcat default port which is 8080.
The template initial configuration establishes that all rest services stays below webresources. This could be easily changed but this is a subject for other post.
Hope you enjoyed it and see you later.
Source:
http://docs.oracle.com/cd/E19226-01/820-7627/giqdq/
Pra ganhar um 10 com estrelinha, faltou colocar um mvn eclipse:eclipse.
ReplyDelete;)
Parabéns Ivan pela iniciativa.
Opa valeu Aryel :)
ReplyDeleteOla Ivan parabens pelo post me ajudou muito ! Voce teria algum exemplo utilizando json?
ReplyDeleteObrigado pelo feedback Rodrigo. No meu github https://github.com/ivanjunckes/rest-client-api-example tem um exemplo de como fazer com JSON. Basicamente vocĂȘ vai ter que mudar o valor dentro de @Produces para application/json.
ReplyDeleteAbs
Great post thanks for sharing such stuff
ReplyDeletelinux training in chennai | best linux training institute in chennai | red hat linux training in chennai
ReplyDeleteGreetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
Best AWS Training in Chennai | Amazon Web Services Training Institute in Chennai Velachery, Tambaram, OMR
Advanced AWS Training in Bangalore |Best AWS Training Institute in Bangalore BTMLA ,Marathahalli
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeletemicrosoft azure training in bangalore
rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in bangalore
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteBest Devops Training in pune
Devops Training in Bangalore
Power bi training in Chennai
Microsoft azure training in Bangalore
I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love
ReplyDeletepython Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
Digital Marketing Training | Digital Marketing Training in Chennai | Digital Marketing Course | Digital Marketing Course in Chennai | Digital Marketing Training Institute | Digital Marketing Training Institute in Chennai | Digital Marketing Course Fees | Digital Marketing Course Online | Digital Marketing Course Online | Digital Marketing Course Fees in Chennai
ReplyDeleteJava Training | Java Training Institute | Java Training in Chennai | Java Training Institute in Chennai
mobile whatsapp groups
ReplyDeleteHey, thank you a lot for sharing this article with us. I can’t say how grateful we are to read this. Also, I would love to share it with my friends and family, who are interested. I hope you will publish such articles in the future as well. It’s so helpful. Goodbye!
ReplyDeleteWonderful post and more informative!keep sharing Like this!
ReplyDeleteSalesforce Training in Hyderabad
Salesforce Training in Pune
The 8 best Casino Sites for Slots - Lucky Club
ReplyDeleteThe 8 best Casino Sites for Slots · 1. 888 Casino – The 8 best casino site for slots · 2. Betway – Best for slots · 3. Playtech – The best casino site · luckyclub 4. Microgaming –