RESTful web services in 15 minutes

How to get started?

4
1126
Ready... Set... GO...
Learn on Udemy Today!

Are you on the urge to implement or start developing RESTful web services with Java?

You are at the right place…

Ok. Start your timer and we will finish the whole exercise in 15 minutes. I assume you have already installed Java, Maven in your system.

To start off with, you first execute the following Maven command in the console of your choice.

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=<groupid> -DartifactId=<artifactid> -Dpackage=<package-name> -DarchetypeVersion=2.19

NOTE: Change groupid, artifactid and package-name

Something like this,

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.cloudskol -DartifactId=restful -Dpackage=com.cloudskol.restful -DarchetypeVersion=2.19

After you execute the above command you will see the project skeleton is created like below.

Hurrah! 50% work is done!

folder

Our next goal is to compile and run our application.

Compile and Package:

Navigate inside our newly created project folder and execute the command

mvn clean package

Run:

Take the generated war file, and put it inside any Java web container and run your web server. Hit http://localhost:8080/restful into your browser and you will see the output in your browser.

STOP! I hope we have NOT yet completed the 15 minutes timings.

Yeah! we are done with our first RESTful web service implementation with Java.

Recommended books: RESTful Java with JAX-RS and RESTful Web APIs

SHARE
Next articleTime saving hacks for webservice development
Thamizharasu is a Java developer living in India. He is writing about Java programming, RESTful web services and frameworks. He also loves working with Web API, Elastic search and Firebase. Currently he is a Madras JUG lead and you can follow him on Twitter @zarub2k