I am following this link for creating a simple Java restApi in Eclipse: https://www.youtube.com/watch?v=5jQSat1cKMo.
However, I am getting a 404 response and console reports an error of
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer.class
It's a dynamic web project and web.xml is as follows:
<?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>JavaAPI</display-name>
<servlet>
<servlet-name>JAVA_API</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer.class</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAVA_API</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
The Hello.java is :
package test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Hello {
@GET
@Produces(MediaType.TEXT_XML)
public String sayHello() {
String resource = "<? xml version='1.0' ?>" +
"<hello> Hi eesh, hello from xml</hello>";
return resource;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public String sayHelloJASON() {
String resource = null;
return resource;
}
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHelloHTML() {
String resource = "<h1> hi eesh, from html</h1>";
return resource;
}
}
The tomcat version is 8.5, jax-rs-2.25..
localhost:8080 doesn't show the apache home page in the chrome browser and on executing the program on the tomcat server...I get the below response..
I have referred this issue in other links:
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer Jersey Services with Tomcat and Eclipse
I have tried most of the solutions and none of them seem to work. Moreover, I wanted to do this without converting it to a maven project.
Any help is appreciated.