Jersey + Jetty + Gradle 404错误 - 但在Tomcat中有效

时间:2015-04-05 14:32:49

标签: gradle jersey jetty

尝试将Jetty Gradle插件添加到当前项目中。我的战争在Tomcat部署中运行良好,但Jetty似乎爆炸了404错误 - 好像它没有正确读取web.xml(验证它在那里)。

localhost:8080 / rest / test< - 在Tomcat中工作

localhost:8080 / rest / test< - 404在Gradle中运行jettyRun(war)

我的简化代码(Java)

package testPackage;
//includes...
@Path("test")
public class TestResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String testResponse() {
        return "test";
    }
}

build.grade

apply plugin: 'java'
apply plugin: 'jetty'

repositories {
    mavenCentral()
}

dependencies {
    compile "javax.ws.rs:jsr311-api:1.1.1"
    compile 'com.sun.jersey:jersey-bundle:1.19'
}

Web.xml中

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

    <servlet>
        <servlet-name>Jersey</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>testPackage</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

1 个答案:

答案 0 :(得分:1)

我的build.grade需要以下内容:

jettyRun.contextPath = ''