users@jersey.java.net

[Jersey] Re: Question about PackagesResourceConfig usage

From: NBW <emailnbw_at_gmail.com>
Date: Wed, 9 Mar 2011 16:07:44 -0500

Hi Martin,

Thanks for your suggestion. I gave it a shot but no joy. I added back the
sun-web.xml with context-root set appropriately, left out the web.xml and
annotated my 'application' class which extends PackagesResourceConfig with
@ApplicationPath("/") (even though this is not in the example in the user's
guide).

In a previous Jersey 1.0 application that I wrote and deployed to GFv3 &
Servlet 2.5 I had things set up like so:

no web.xml
no sun-web.xml
a class that extended Application and was annotated with
@ApplicationPath("/api")

and things worked, my Root resource classes were 'auto discovered' in that
case.

-Noah

On Wed, Mar 9, 2011 at 3:46 PM, Martin Matula <martin.matula_at_oracle.com>wrote:

> 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/hwwhere 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
>