I am using jersey to create a web server
my project directory has the following mapping
ProjectName
|.. src/main/java
|.. folder1
|.. restEndpoint1.java , restendpoint2.java etc
an example of how restEndpoint1.java looks is
@Path("/static1/static2")
public class DoStuff {
@POST
@Path("/static3")
@Consumes(MediaType.APPLICATION_XML)
@Produces("application/xml")
public Response validation(String inputXML){
so an example of my url when deployed to tomcat is
localhost:port/projectName/foldername/{restendpoint1.path}
my web.xml is
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>folder1</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/folder1/*</url-pattern>
</servlet-mapping>
Now I have to deploy this war as different contexts using the Context path in the tomcat web UI ( I am using Tomcat 7)
ie I would like the url's to be
http://localhost:port/{context1}/{restendpoint1.path}
http://localhost:port/{context2}/{restendpoint1.path}
I know that each context will have all the rest endpoints exposed to them but I dnt care about that , I just need to map it this way . The problem I am facing is
1) in the web.xml I need to give a folder name as the param so that becomes a root , but with this context requirement I cannot do it . Also I cannot map to each java class independently ( can I??)
2) In the tomcat UI how do I deploy my app using different contexts , I can only upload war or give the context and using a URL of the war on a server
Solved by changing the mapping in the web.xml
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/folder1/*</url-pattern>
</servlet-mapping>
to
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.