users@jersey.java.net

[Jersey] Re: Question about PackagesResourceConfig usage

From: Martin Matula <martin.matula_at_oracle.com>
Date: Wed, 9 Mar 2011 12:46:53 -0800 (PST)

Hi,
You need to annotate your application class with @ApplicationPath("/") annotation. This replaces the servlet and servlet mapping entry in the web.xml. You still need to keep the sun-web.xml to specify application context path:
<sun-web-app error-url="">
<context-root>/contextRoot</context-root>
</sun-web-app>
Martin

----- Original Message -----
From: emailnbw_at_gmail.com
To: users_at_jersey.java.net
Sent: Wednesday, March 9, 2011 8:59:30 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: [Jersey] Question about PackagesResourceConfig usage

I was trying to try out the approach of deploying my Jersey service by extending PackagesResourceConfig as is done in Example 2.8 of the User's Guide [1]. My class looks like this:


package com.myapp.ws.rs ;


public class TestApplication extends PackagesResourceConfig {
public TestApplication() {
super("com.myapp.api");
}
}


I have a Servlet 3.0 web.xml file, however, it simply contains the <web app .. > element. I also have a 3.0 sun-web.xml which is empty right now save for the DOCTYPE and an empty <sun-web-app> element.


My Provider resource class looks like this (some content omitted):


@Path("/foo")
@Stateless
public class FooTest {


@EJB
FooBean aFooBean;


@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/hw")
public Response getHW() {
return Response.ok("hello, world").build();
}


....


I get a 404 when I try to access http://localhost:8080/contextRoot/foo/hw where contextRoot is the cr for my web app. This test code deploys and works fine when I take the servlet 2.5 web.xml approach of using the Jersey ServletContainer servlet.


Any hints as to what I am missing with this other approach? Thanks,


-Noah



[1] - http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e194