java - Gradle Exec Task 停止tomcat

标签 java tomcat gradle cmd gradlew

我在这里查看此文档: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/

相关文章:

java - 无法访问 GraphNode 内的对象

eclipse - 在 eclipse 中将 GWT 应用程序部署到 tomcat 的问题

java - 由 : java. lang.ClassNotFoundException : oracle. jdbc.OracleDriver 引起

gradle - 将文件夹添加到 srcDir 除了 gradle 中的一个文件

gradle - Gradle compileJava任务跳过Hibernate映射文件

java - Spring应用程序无法识别

java - fatal :unable to update url base from redirection. ..无法解决

java - 在服务器端处理动态表单

java - Hibernate:继承映射到遗留数据库

Java Web 错误 : Error : running Tomcat 7. 0:找不到 jsp 内置 servlet 的配置