Home > Software Development > Starting with JAX-RS: Configuring javax.ws.rs.ApplicationPath

Starting with JAX-RS: Configuring javax.ws.rs.ApplicationPath

I recently started with a very simple Hello-World-like JAX-RS. So, to start with, I created a class like this:


package com.wordpress.dwuysan;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path(value = "generic")
public class GenericResource {

    public String get() {
        return "Hello World";

Once the application server is running, when I run curl http://<web application address>/generic, it failed.

After a little bit of Google-ing around, I found that you need to set up the resource path, either by installing a correct servlet on web.xml, or if you are fortunate enough and are using Java EE 6, you can use @javax.ws.rs.ApplicationPath and extends javax.ws.rs.core.Application (Kuchtiak 2009).

So, once I add this class:


package com.wordpress.dwuysan;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath(value = "resources")
public class ApplicationConfig extends Application {

I can now invoke curl http://<web application address>/resources/generic, I got correct response.


Kuchtiak, M, 2009, 'How to Combine REST Services with EJB 3.1', accessed 06 December 2012.

Categories: Software Development Tags:
  1. No comments yet.
  1. December 6, 2012 at 6:00 am
  2. February 13, 2013 at 7:16 am

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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


Get every new post delivered to your Inbox.

Join 34 other followers