I am new to Gradle and I am using a small task to start/stop local tomcat server.
My gradle task:
task startTomcat(type: Exec){
workingDir ENV['CATALINA_HOME'] + '/bin'
commandLine 'cmd', '/c', 'catalina.bat'
args 'start'
}
When I run this task, tomcat does start. But the task is not completing and keeps on waiting. I have gone through Exec documentation page but could not get any clue.
Please help.
Thanks Peter for the input. Here is the solution that worked for me using ProcessBuilder:
/* Configuration for tomcat */
task catalinaConfig {
ext.binDir = ENV['CATALINA_HOME'] + "\\bin"
}
task startTomcat << {
println "Tomcat path: " + catalinaConfig.binDir
ProcessBuilder pb = new ProcessBuilder(["cmd", "/c", "catalina.bat", "start"]);
pb.directory(new File(catalinaConfig.binDir));
println "Starting tomcat now ... "
Process proc = pb.start();
proc.waitFor();
println "Tomcat is coming up now ... " + proc.exitValue()
}
task stopTomcat << {
println "Tomcat path: " + catalinaConfig.binDir
ProcessBuilder pb1 = new ProcessBuilder(["cmd", "/c", "catalina.bat", "stop"]);
pb1.directory(new File(catalinaConfig.binDir));
println "Stopping tomcat now ... "
Process proc1 = pb1.start();
proc1.waitFor();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With