问题
I have a jersey java dynamic web project...a web service which i think is laid out correctly (hoping im wrong though). This web service runs off tomcat8.5 server on my win 10 laptop.
When Tomcat is manually started in services I can hit its home page at localhost:8081.
When i run my web service in eclipse i am denied with http 404 error 'request resource isnt available'. I cant even hit the localhost:8081 the same way i can when i start it manually and i cant see it started in 'services'...but eclipse says it is started. I see lots of red info warnings on startup but cant see any issue.
Help please!
Heres my setup:
Libs
Build Path
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>MyApi</display-name>
<servlet>
<display-name>Rest Servlet</display-name>
<servlet-name>RestServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>
Java class
package ws;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@Path("test")
public class Connect {
@GET
@Path("test")
@Produces(MediaType.TEXT_PLAIN)
public String hello(){
return "hello world";
}
}
My error
来源:https://stackoverflow.com/questions/42211334/tomcat-gives-http404-error-when-used-to-test-jersey-java-web-service