问题
Trying to start tomcat using this gradle code snippet
task startTomcat(type:Exec) {
workingDir tomcat_home + "\\bin"
commandLine 'cmd', '/c', 'startup.bat'
}
After run this task tomcat is starting but gradle build process is hanged(waiting). How to solve this problem?
回答1:
You can run this task in background but it will be maybe not difficult but problematic to keep control of the running process (e.g. stopping it on demand - which might be solved by adding stopTomcat
task). What You need is the following piece of code:
task startTomcat << {
def processBuilder = new ProcessBuilder(['cmd','/c','startup.bat'])
processBuilder.directory(new File("$tomcat_home\\bin"))
processBuilder.start()
}
I don't guarantee that this will work as is because I don't have any windows workstation to try it out, but this is the code that should do the job after (maybe required) some altering.
来源:https://stackoverflow.com/questions/26943091/how-to-speed-up-the-tomcat-starting-process-in-gradle