user3673948
user3673948

Reputation: 99

Gradle Exec Task to stop tomcat

I am looking at this documentation here: https://docs.gradle.org/3.4.1/dsl/org.gradle.api.tasks.Exec.html which gives an example how to turn off/on tomcat.

However its not explained very well what exactly parameters commandLine expects.

So, the code below is failing. Could you please share any thoughts ?

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()
    }
}

I have configured my task as above, but it does fail when i run the task.

Caused by: net.rubygrapefruit.platform.NativeException: Could not start './catalina stop'

Upvotes: 1

Views: 1137

Answers (1)

Michael Easter
Michael Easter

Reputation: 24468

Are you using Windows or Unix?

Generally, you need to identify the appropriate command that works for you at a command-line terminal on your platform. Then use the appropriate "platform style" in your Gradle task.

For example, I have Tomcat 7.x. To shutdown on Unix, using a terminal in $TOMCAT_HOME/bin, I would use ./shutdown.sh. In this case, the task would use only:

  commandLine './shutdown.sh' 

On Windows, I would use shutdown.bat. In this case, the task would use:

  commandLine 'cmd', '/c', 'shutdown.bat'

Note that it is using cmd to call the BAT file. Because of the way Windows works, the commandLine would have that form for any BAT file.

Upvotes: 1

Related Questions