Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

tomcat - Gradle Exec task not exiting

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...