Search code examples
javarestservletsjersey-2.0

java dynamic server - can i have multiple web.xml files?


I'm using Jersey for restful service deserialization and in the web.xml file it is declared that i must declare the package name where my resources will be. so it ends up looking like this in web.xml:

   <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
     <!-- Register resources and providers under com.vogella.jersey.first package. -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
<!-- this is my package name where my jersey resources are kept -->
        <param-value>com.vogella.web.resources</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

now onto my question, what if i wanted to have jersey resources in other packages, could i create another web.xml file or how is it done ?


Solution

  • The packages can be comma separated list.

    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <!-- this is my package name where my jersey resources are kept -->
        <param-value>com.vogella.web.resources, com.vogella.web.resources1</param-value>
    </init-param>