Gradle嵌入式码头插件不会自动停止 [英] Gradle embedded jetty plugin is not stopping automatically
问题描述
我能够使用gradle jettyRunWar命令运行嵌入式码头。但是,它不会在程序终止时自动停止。
在搜索stackoverflow和其他论坛上的解决方案后,我尝试了两个代码。但无效。
<1> build.gradle
apply plugin :'jetty'
任务runJetty(){
jettyStop.stopPort = 8090
dependsOn jettyRunWar
finalizedBy jettyStop
}
<2> build.gradle
apply plugin:'jetty'
task runJetty(){
doFirst {
jettyRunWar.stopPort = 8090
jettyRunWar.stopKey ='stopKey'
jettyRunWar.daemon = true
tasks.jettyRunWar.execute()
}
doLast {$ b $ $ jettyStop.stopKey ='stopKey'
tasks.jettyStop.execute()
}
}
在这两种情况下,在运行runJetty任务时,嵌入式jetty服务器都会启动,但程序终止时不会停止。
FWIW:我使用Eclipse External Tools Configuration来启动并启动termi nate build.gradle。并且,在URL中使用8080端口进行测试。
<2>尝试将stopPort设置为其他值,例如8090 。
我认为你实际上是在8080上运行jetty,这样端口就会被占用,你无法建立一个'stop'监听器。
否则,你可以在你的build.gradle中放入以下内容:
//需要设置stopPort和stopKey,所以我们可以停止码头!
jettyRunWar.stopPort = 8090
jettyRunWar.stopKey ='stopKey'
jettyStop.stopPort = 8090
jettyStop.stopKey ='stopKey'
下面是一个适用于我的例子:intelliJ
http://pastebin.com/eTtvCdTb
<我>在intelliJ的Gradle任务面板中运行jettyRunWar和jettyStop。我只为jettyRun设置了参数,以防万一我意外运行该任务,我可以关闭服务器。
I am able to run embedded jetty with gradle jettyRunWar command. However, it is not automatically stopped on program termination.
I tried below two code after searching the solution on stackoverflow and other forums. But none works.
1) build.gradle
apply plugin: 'jetty'
task runJetty() {
jettyStop.stopPort = 8090
dependsOn jettyRunWar
finalizedBy jettyStop
}
2) build.gradle
apply plugin: 'jetty'
task runJetty() {
doFirst {
jettyRunWar.stopPort = 8090
jettyRunWar.stopKey = 'stopKey'
jettyRunWar.daemon = true
tasks.jettyRunWar.execute()
}
doLast {
jettyStop.stopPort = 8090
jettyStop.stopKey = 'stopKey'
tasks.jettyStop.execute()
}
}
In both cases, on running runJetty task, embedded jetty server starts but did not stop on program termination.
FWIW: I am using Eclipse External Tools Configuration to start and terminate build.gradle. And, using 8080 port in the url to test.
In 2) try setting the stopPort to something else, such as 8090.
I think you are actually running jetty on 8080 so that port will be occupied and you are unable to set up a 'stop' listener.
Otherwise you can just put the following in your build.gradle
// need to set the stopPort and stopKey so we are able to stop jetty!
jettyRunWar.stopPort = 8090
jettyRunWar.stopKey = 'stopKey'
jettyStop.stopPort = 8090
jettyStop.stopKey = 'stopKey'
Here is an example that worked for me in intelliJ http://pastebin.com/eTtvCdTb
I run 'jettyRunWar' and 'jettyStop' from the Gradle tasks panel in intelliJ. I've only set the parameters up for jettyRun just in case I run that task by accident, I can then shut the server down.
这篇关于Gradle嵌入式码头插件不会自动停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!