Search code examples
javarestjerseyweb.xml

Jersey web.xml file <init-param>


I am new to REST services using Jersey.

My project is entitled: cs9322.simple.rest.books.resources

I have question regarding the web.xml file which contains the following parts:

<init-param>
   <param-name>com.sun.jersey.config.property.packages</param-name>
   <param-value>cs9322.simple.rest.books.resources</param-value>
</init-param>

<servlet-mapping>
   <servlet-name>Jersey REST Service</servlet-name>
   <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

I find that even if I change:

<param-value>cs9322.simple.rest.books.resources</param-value>

TO

<param-value>cs9322.simple.rest.books</param-value>

I still have to access the service through the URL: cs9322.simple.rest.books.resources/rest/*

I don't understand what <param-value>cs9322.simple.rest.books.resources</param-value> refers to exactly, because it seems that the base url for the service is always the project name and isn't influenced by <param-value>.

Could someone please explain to me what <param-value> refers to?

Thank you for your help.


Solution

  •  <param-value>cs9322.simple.rest.books.resources</param-value>
    

    OR

     <param-value>cs9322.simple.rest.books</param-value>
    

    has no relation to your REST service URL. Above parameter is used to scan the files to be exposed as REST services by jersey framework.

    It is the name of your project/web context that is used when accessing the REST service URL. So your web context seems to be cs9322.simple.rest.books.resources and hence you have to use that as the base URL.