Error deploy java jersey with Tomcat 8.5

2

I am using IDE Myeclipse CI 10 , the code works perfectly when publishing and consuming the service from my IDE, but when I deploy the service I tried to consume it from my server Tomcat 8.5 shows me an error.

Java code

package logic;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.sun.jersey.spi.resource.Singleton;

@Produces("application/xml")
@Path("test")
@Singleton
public class Principal {
 public Principal(){}

 @GET
 @Path("alfa")
 @Produces(MediaType.APPLICATION_JSON)
 public String hello(){
     return "Hello";
 }
}

I use Postman to test from my IDE and it works. I export the .war and from the Manager app of tomcat I deploy the .war, it is displayed correctly but when I use it it shows me the following error

Configuring my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Simple</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description>JAX-RS Tools Generated - Do not modify</description>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/jaxrs/*</url-pattern>
  </servlet-mapping>
</web-app>

Configuring my /opt/tomcat/webapps/host-manager/META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
 <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPre$
</Context>
    
asked by Rastalovely 07.05.2018 в 16:23
source

1 answer

1

It is possible that your IDE has already added in the classpath the necessary package, while Tomcat needs you to add to your project (I assume you use Maven) the following dependency:

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>
    
answered by 07.05.2018 / 16:41
source