How do I specify multiple <param-value>
for a given <param-name>
under servlet's <init-param>
tag. Following is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>com.vogella.jersey.first</display-name>
<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>
<param-value>com.vogella.jersey.first</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>
</web-app>
The parameter jersey.config.server.provider.packages defines in which package Jersey will look for the web service classes.
I want to specify multiple package names here, as my service classes are in different packages. Something like following, but none of them works:
1) Multiple <param-value>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
<param-value>com.vogella.jersey.second</param-value>
</init-param>
2) Multiple <init-param>
<servlet>
...
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.second</param-value>
</init-param>
How do I do this?
You can't specify multiple <param-value>
for a single <param-name>
.
Use this instead:
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.pack.first;com.pack.rest.second</param-value>
</init-param>
;
and ,
can be used as a separators.
Credit to Ramanlfc's answer, you can use "," as package separator too. For example:
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.pkg.first,com.pkg.second</param-value>
</init-param>
Tested under Ubuntu 16.04.2, tomcat-8.5.11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With