Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jersey 2.x(非Maven)在Tomcat服务器上运行时给出404错误_Java_Rest_Tomcat_Jersey_Jersey 2.0 - Fatal编程技术网

Java Jersey 2.x(非Maven)在Tomcat服务器上运行时给出404错误

Java Jersey 2.x(非Maven)在Tomcat服务器上运行时给出404错误,java,rest,tomcat,jersey,jersey-2.0,Java,Rest,Tomcat,Jersey,Jersey 2.0,我一直在尝试为我的RESTful应用程序设置Jersey,但进展不顺利。我不喜欢maven方法,因为我不太理解jersey文档中提供的初始maven结构。。它包含许多额外的依赖项,这些依赖项会混淆和产生问题 因此,我在eclipse中使用tomcat server 7建立了一个新的简单web项目,可以肯定的是,仅在初始测试时,就将所有JAR转储到构建路径中。(尽管即使对于基本的jersey实现,它也需要大量JAR,这很奇怪) 问题: 1) 完成上述所有步骤后,当我启动tomcat服务器时,它总是

我一直在尝试为我的RESTful应用程序设置Jersey,但进展不顺利。我不喜欢maven方法,因为我不太理解jersey文档中提供的初始maven结构。。它包含许多额外的依赖项,这些依赖项会混淆和产生问题

因此,我在eclipse中使用tomcat server 7建立了一个新的简单web项目,可以肯定的是,仅在初始测试时,就将所有JAR转储到构建路径中。(尽管即使对于基本的jersey实现,它也需要大量JAR,这很奇怪)

问题:

1) 完成上述所有步骤后,当我启动tomcat服务器时,它总是给我一个404错误。。控制台没有显示错误,但也没有显示服务器处于活动状态http://localhost:8080/

另外,我正在使用最新的I.e 2.9版本的球衣

我的所有代码和控制台输出如下:

启动服务器时的控制台

Jun 16, 2014 12:36:00 AM 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: /Users/Sahil/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Jun 16, 2014 12:36:01 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
Jun 16, 2014 12:36:01 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:REST test' did not find a matching property.
Jun 16, 2014 12:36:02 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 16, 2014 12:36:02 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 16, 2014 12:36:02 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2339 ms
Jun 16, 2014 12:36:02 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 16, 2014 12:36:02 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
Jun 16, 2014 12:36:06 AM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.9 2014-05-22 05:12:10...
Jun 16, 2014 12:36:06 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jun 16, 2014 12:36:06 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 16, 2014 12:36:06 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4117 ms
WEB.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<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>REST test</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 Web Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.sahilgandhi</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

我真傻,我没有在URL中使用
战争名称。。但我会为任何经历过建立泽西的斗争的人保留这段代码

问题的答案

http://localhost:8080///

所以对我来说是->
http://localhost:8080/REST_Test/rest/testapi

学分:

package com.sahilgandhi.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.sahilgandhi.data.User;

/**
 * Root resource (exposed at "testapi" path)
 */
@Path("testapi")
public class TestApi {

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getIt() {
        return "works like a dream!!"; // I HOPE IT DID! :(
    }

}