【问题标题】:Gradle Exec Task to stop tomcatGradle Exec任务停止tomcat
【发布时间】:2017-08-06 18:16:57
【问题描述】:

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

我已经按照上面的方式配置了我的任务,但是当我运行任务时它确实失败了。

原因:net.rubygrapefruit.platform.NativeException:不能 开始'./catalina stop'

【问题讨论】:

    标签: java tomcat gradle cmd gradlew


    【解决方案1】:

    您使用的是 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 文件都具有该格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多