Please pay attention to comments in web.xml and other examples!
From what I see a problem with ServletContainer! Or I have the wrong settings?
I would be glad if someone explains why when using a container in my case, I get 404?
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <description>JerseyTesting</description> <servlet-name>WebService</servlet-name> <servlet-class>web.service.JerseyDemo</servlet-class> // When i use this construction -> upper //i got the response as needed! <description>JerseyTesting</description> <servlet-name>WebService</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> //When i using this construction I got 404 not found, at the same url path! </servlet> //Here the mapping <servlet-mapping> <servlet-name>WebService</servlet-name> <url-pattern>/users/*</url-pattern> </servlet-mapping> </web-app> ================================================= =================
// Using it with: And this working! //<description>JerseyTesting</description> //<servlet-name>WebService</servlet-name> //<servlet-class>web.service.JerseyDemo</servlet-class> @Path("users") public class JerseyDemo extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); writer.print("Hello from Servlet"); } } ======================================================================
// Using it with: And this not working 404 not found error! //<description>JerseyTesting</description> //<servlet-name>WebService</servlet-name> //<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> @Path("users") public class JerseyDemo { @GET @Produces(MediaType.APPLICATION_JSON) public String getResponse(){ return "Hello From Jersey Servlet"; } } ======================================================================
web lib folder:
Using it with: And this working! <description>JerseyTesting</description> <servlet-name>WebService</servlet-name> <servlet-class>web.service.JerseyDemo</servlet-class> <!-- <servlet> <servlet-name>WebService</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>tests</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> //This method not working!! 404 Error! --> <servlet> <servlet-name>WebService</servlet-name> <servlet-class>tests.JerseyServiceDemo</servlet-class> <load-on-startup>1</load-on-startup> // This method Working! </servlet> <servlet-mapping> <servlet-name>WebService</servlet-name> <url-pattern>/users/*</url-pattern> </servlet-mapping> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.testing.functionality</groupId> <artifactId>TestingProjects</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>TestingProjects Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19</version> </dependency> </dependencies> <build> <finalName>TestingProjects</finalName> </build> </project> 
