Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Tomcat server launched from an Eclipse Gradle Plugin?

I'm running through a tutorial from http://spring.io about RESTful webservices.
I wanted to be able to launch my web project from Eclipse as a Gradle build (Run As => Gradle Build...) and then stop it when I'm done testing it.
I know how to start it, but I just can't get it to stop without quitting Eclipse (Spring Tool Suite).

Any Suggestions?

like image 203
Jonathan Avatar asked Dec 26 '13 20:12

Jonathan


1 Answers

To borrow from the Gradle Tomcat plugin documentation, just do this:

ext {
    tomcatStopPort = 8081
    tomcatStopKey = 'stopKey'
}

task doTomcatRun(type: org.gradle.api.plugins.tomcat.TomcatRun) {
    stopPort = tomcatStopPort
    stopKey = tomcatStopKey
    daemon = true
}

task doTomcatStop(type: org.gradle.api.plugins.tomcat.TomcatStop) {
    stopPort = tomcatStopPort
    stopKey = tomcatStopKey
}

task someTask(type: SomeGradleTaskType) {
    //do stuff
    dependsOn doTomcatRun
    finalizedBy doTomcatStop
}

In this example, someTask is a Gradle task that you execute where Tomcat is started before the task runs and Tomcat is stopped after the task completes.

If you prefer something more manual, then simply configure and then run the tomcatStop task via Eclipse:

tomcatStop {
        stopPort = 8090
        stopKey = 'foo'
}
like image 124
Vidya Avatar answered Oct 22 '22 16:10

Vidya