Simple jax-rs java restful rest eclipse maven example

After failing to get anything running from “Restful Java with JAX-RS 2.0”, you need to see if you can get the minimal setup running. Here’s how.

New dynamic web project.  Project name: rest   Finish

Right click rest in project explorer // Configure // convert to Maven project // Finish.

pom.xml should show in the window.  At the bottom of the window, click the tab for “pom.xml” so that you can edit the xml source code:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

Right click on the rest project in project explorer.  New// class//package mystuff // Name Timezone// Finish

Enter this stuff:

package mystuff;


public class Timezone {

	public String timezone() {
		return "time to party";

	public String myfunction(@PathParam("myverb") String myverb) {
		return "{\"time\" : \"" + myverb + "\"}";

Find the folder WebContent/WEB-INF, right click on it,


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="" xmlns:web="" xmlns:xsi="" xsi:schemaLocation="" version="3.0">

right-click the rest project in Package explorer.  Run as // Maven install

right-click the project rest and run as // run on server // Tomcat 9

Go to Chrome/Firefox and enter the following URL:


time to party

Now enter this url:


{"time" : "sing"}

Next steps:

1. create with path of “/” showing a welcome message to the site, and output it in HTML.

2. Create a new method in the Timezone class that accepts POST requests.

I didn’t implement POST, because the goal is to get something running, and implementing POST before GET is a huge drain on your time. With GET, you can experiment much easier with a browser.

To test your POST, install Postman in Chrome. I use restlet client in Chrome myself, it’s more lightweight.

A good book on how to write APIs correctly is “Rest API Design Rulebook”. I didn’t follow its rules here, it wasn’t my objective. I took a few shortcuts too, like using * with imports, which is a bad thing.

I was shocked after reading the Java JAX-RS book how much of a complicated example he made right at the start. I thought it’d be a huge hurdle to learn enough to get something basic running, but this example proves otherwise. Too bad he didn’t start off with an example like this. (You can use that idea, Bill Burke!)

If you found any of this helpful, share the luv, leave a thanks below 🙂


About SunKing2

Former web developer, guitar player, started Piano 2012 -yes still doing it! Recovery, sobriety, mental health advocate.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s