Java web service (jersey) on tomcat only works when starting from eclipse

I have developed several web services using Eclipse and Jersey and Tomcat 7 as a server.

When you start a project from Eclipse, everything works fine. However, when deploying the project WAR file directly to Tomcat (using its manager), I get a 404 error when calling the service.

My WEB-INF \ lib directory contains all jersey libs.

my web.xml:

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>myApp</display-name> <welcome-file>index.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>myApp REST Service</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>com.myapp.resources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>myApp REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> 

I believe that I have something missing in the Tomat configuration, but I have no idea ...

Any idea?

Ahanks, Assaf

+4
source share
2 answers

ok ...

The problem is solved by taking the following two actions:

a. by configuring the following \ tomcat \ conf \ server.xml entries, replacing the "localhost" attribute with the actual server name:

 <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> 

b. while taking care of the Windows firewall to allow incoming HTTP: 8080. I feel a little confused - for some reason, I thought setting Amazon security rules was enough (-:

Thank you for attention.

Assaf

0
source

Try this one ...

 <servlet> <servlet-name>jersey-serlvet</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.hrms.admin.jersey.service</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-serlvet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> 

Visit This: Jersey

0
source

Source: https://habr.com/ru/post/1443552/


All Articles