我在这里查看此文档:https://docs.gradle.org/3.4.1/dsl/org.gradle.api.tasks.Exec.html这给出了一个如何关闭/打开 tomcat 的示例。
然而,它并没有很好地解释 commandLine 期望的参数到底是什么。
所以,下面的代码是失败的。您能分享一下您的想法吗?
task stopTomcat(type:Exec) {
println "$System.env.TOMCAT"
workingDir "${System.env.TOMCAT}" + '/bin/'
//on windows:
commandLine './catalina.sh stop'
//on linux
//commandLine './stop.sh'
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
//extension method stopTomcat.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}
我已经按照上面的方式配置了我的任务,但是当我运行任务时它确实失败了。
Caused by: net.rubygrapefruit.platform.NativeException: Could not start './catalina stop'
最佳答案
您使用的是 Windows 还是 Unix?
通常,您需要在平台的命令行终端上确定适用于您的适当命令。然后在您的 Gradle 任务中使用适当的“平台样式”。
例如,我有 Tomcat 7.x。要在 Unix 上关闭,使用 $TOMCAT_HOME/bin
中的终端,我会使用 ./shutdown.sh
。在这种情况下,任务将仅使用:
commandLine './shutdown.sh'
在 Windows 上,我会使用 shutdown.bat
。在这种情况下,任务将使用:
commandLine 'cmd', '/c', 'shutdown.bat'
请注意,它是使用cmd
来调用BAT 文件。由于 Windows 的工作方式,命令行对于任何 BAT 文件都将具有该形式。
关于java - Gradle Exec Task 停止tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45535148/