Creating a RESTful Service with Java and Jersey with Netbeans

2014-11-29

Mark Tsibulski

Creating a RESTful Service with Java and Jersey with Netbeans

Step-by-step tutorial on creating RESTful services using Java, Jersey, and NetBeans with MySQL.

There are many ways to implement a RESTful service, but what if you need to do it in Java and you use Netbeans?

First, fire up Netbeans and create a new Maven Web Application project. Give it a name of your choosing.

Right off the bat, create a web.xml file by right clicking on the project and creating a new Standard Deployment Descriptor.

And the last configuration step you will need to make before you actually write code is to add the Jersey Dependency to your pom.xml.

Now you can get to writing some code. To begin, create a Java class and add the appropriate JAX-RS annotations.

In order for this to work, you must make an addition to your web.xml to map the Java class to the RESTful path.

I use Jetty as a server because it’s simple to use, it recompiles/restarts on save, and it’s also easy to set up.

Working with Java can be confusing sometimes, but once you setup your environment, it becomes a breeze. With the code above, you now have a baseline to work from, and it becomes easy to implement CRUD operations into your project.