Rest 404与jersey 1.8、tomcat 7 Resful和eclipse一起未找到

Rest 404与jersey 1.8、tomcat 7 Resful和eclipse一起未找到,rest,jakarta-ee,tomcat,jersey,Rest,Jakarta Ee,Tomcat,Jersey,我是J2EE新手,我想创建一个restful web服务,因此我遵循了一个教程,并在此基础上在eclipse(开普勒服务发行版1)中创建了一个简单的动态web应用程序项目,然后添加了jersey 1.8库,并配置了appache tomcat(apache-tomcat-7.0.50)使用eclipse,在添加index.html之后,我可以看到http://localhost:8080/myproject/页面内容 但我得到错误404(nt发现)与此url http://localhost:8

我是J2EE新手,我想创建一个restful web服务,因此我遵循了一个教程,并在此基础上在eclipse(开普勒服务发行版1)中创建了一个简单的动态web应用程序项目,然后添加了jersey 1.8库,并配置了appache tomcat(apache-tomcat-7.0.50)使用eclipse,在添加index.html之后,我可以看到
http://localhost:8080/myproject/
页面内容

但我得到错误404(nt发现)与此url

http://localhost:8080/myproject/api/v1/status

这是java资源文件

package myproject;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/v1/status/*")
public class v1_status {

private static final String api_version = "00.01.00";

@GET
@Produces(MediaType.TEXT_HTML)
public String returnName(){
    return "<p>Web Services</p>";
}

@Path("/version")
@GET
@Produces(MediaType.TEXT_HTML)
public String returnVersion()
{
    return "<p>Web Services</p>" + api_version; 
}

  }

解决后,
@路径(“/v1/status/*”
中的星号
(*)
是问题的原因
删除它之后,我得到了正确的结果,因此它应该是
@Path(“/v1/status/”)

Jersey映射到/api/*。您的资源路径是
/status/*
。为什么您认为它会被映射到
/api/v1/status
而不是
/api/status
?@JBNizet我在测试中这样做了,资源映射实际上是映射到了“/v1/status/”,结果与旧的(404)相同。您可以尝试一下“”@indownight 404错误吗
package myproject;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/v1/status/*")
public class v1_status {

private static final String api_version = "00.01.00";

@GET
@Produces(MediaType.TEXT_HTML)
public String returnName(){
    return "<p>Web Services</p>";
}

@Path("/version")
@GET
@Produces(MediaType.TEXT_HTML)
public String returnVersion()
{
    return "<p>Web Services</p>" + api_version; 
}

  }
 <?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"
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>myproject</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>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <!-- com.sun.jersey.config.property.packages 
        jersey.config.server.provider.packages  -->
        <param-name>com.sun.jersey.config.property.packages</param-name>            
        <param-value>myproject</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

   </web-app>
Feb 15, 2014 5:04:50 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;E:\oracle\product\10.2.0\client_2\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\Program Files\MATLAB\R2013a\runtime\win64;E:\Program Files\MATLAB\R2013a\bin
Feb 15, 2014 5:04:50 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:myproject' did not find a matching property.
Feb 15, 2014 5:04:51 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 15, 2014 5:04:51 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 15, 2014 5:04:51 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 720 ms
Feb 15, 2014 5:04:51 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 15, 2014 5:04:51 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.50
Feb 15, 2014 5:04:51 PM org.apache.tomcat.websocket.server.WsSci onStartup
INFO: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocketJARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available. 
Feb 15, 2014 5:04:52 PM com.sun.jersey.api.core.servlet.WebAppResourceConfig init
INFO: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
Feb 15, 2014 5:04:52 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class myproject.v1_status
Feb 15, 2014 5:04:52 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
  class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
  class org.codehaus.jackson.jaxrs.JacksonJsonProvider
  class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
  class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
Feb 15, 2014 5:04:53 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.18 11/22/2013 01:21 AM'
Feb 15, 2014 5:04:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 15, 2014 5:04:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 15, 2014 5:04:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2836 ms