[英]Gradle + Embedded Jetty
I have modified an existing Jetty project and after I builded, I got 404. Maybe I need to modify other files which I do not know. 我修改了一个现有的Jetty项目,并在构建后得到404。也许我需要修改其他我不知道的文件。 I am using gradle to build. 我正在使用gradle构建。 Here is the build.gradle : 这是build.gradle:
apply plugin: 'java'
apply plugin: 'jetty'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework:spring-webmvc:4.1.6.RELEASE'
compile 'org.hibernate:hibernate-core:4.3.6.Final'
testImplementation 'junit:junit:4.12'
testCompile 'junit:junit:4.11'
testCompile 'org.hamcrest:hamcrest-all:1.3'
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.14'
}
test {
exclude '**/*IntegrationTest*'
}
task integrationTest(type: Test) {
include '**/*IntegrationTest*'
doFirst {
jettyRun.contextPath = '/';
jettyRun.httpPort = 8080 // Port for test
jettyRun.daemon = true
jettyRun.execute()
}
doLast {
jettyStop.stopPort = 8091 // Port for stop signal
jettyStop.stopKey = 'stopKey'
jettyStop.execute()
}
}
// Embeded Jetty for testing
jettyRun{
contextPath = "spring4"
httpPort = 8080
}
jettyRunWar{
contextPath = "spring4"
httpPort = 8080
}
//For Eclipse IDE only
eclipse {
wtp {
component {
//define context path, default to project folder name
contextPath = 'spring4'
}
}
}
Here the other class: 这里是另一类:
package com.hello.webapp;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import com.hello.service.SignUpService;
@Path("/signUp")
public class SignUpWebapp {
private static SignUpService signUpService = new SignUpService();
@GET()
public String hello() {
return signUpService.sayHello();
}
}
here the simple service: 这里的简单服务:
package com.hello.service;
public class SignUpService {
public String sayHello() {
return "signUp";
}
}
this is another the integration test class 这是另一个集成测试类
package com.hello.webapp;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import org.junit.Test;
public class SignUpIntegrationTest {
private static String SIGNUP = "http://localhost:8080/signUp";
@Test
public void testHello() throws Exception {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(SIGNUP);
String response = webTarget.request().get(String.class);
assertThat(response, is("signUp"));
}
}
So, when I run gradle integrationTest
I get an error saying that Jetty is already running. 因此,当我运行gradle integrationTest
我收到一条错误消息,提示Jetty已经在运行。 And when I try to visit localhost/signUp
I get a 404. 当我尝试访问localhost/signUp
我得到了404。
One solution is to use gretty instead: 一种解决方案是改用gretty:
apply plugin: 'org.akhikhl.gretty'
....
classpath 'org.akhikhl.gretty:gretty:1.4.0'
...
gretty {
port = 8083
contextPath = '/'
servletContainer = 'jetty9'
jvmArgs = [
'-Xms700m',
'-Xmx2048m'
]
loggingLevel='INFO'
debugPort = 5005 // default
debugSuspend = true // default
httpsEnabled = true
httpsPort = 8443
sslKeyStorePath = 'some.jks'
sslKeyStorePassword = 'somepwd'
}
and then gradle appStart 然后gradle appStart
Let me know if that helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.