首页 文章

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

提问于
浏览
1

尝试将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 回答

  • 1

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

    jettyRun.contextPath = ''
    

相关问题