Jonathan
Jonathan

Reputation: 479

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?

Upvotes: 6

Views: 6311

Answers (3)

Benny Lam
Benny Lam

Reputation: 1

In your build.gradle

[tomcatRun, tomcatRunWar, tomcatStop]*.stopPort = 8081
[tomcatRun, tomcatRunWar, tomcatStop]*.stopKey = 'stopKey'

Upvotes: 0

Vidya
Vidya

Reputation: 30310

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'
}

Upvotes: 3

akhikhl
akhikhl

Reputation: 2578

May I humbly suggest you using gradle "jetty" plugin instead. Consider:

a) it supports jettyRun, jettyRunWar and jettyStop tasks.

b) it uses jetty 6 and, therefore, is compatible with servlet-api 2.5 (the equivalent version of tomcat is 6).

If you are not satisfied with too old jetty/servlet-api, feel free trying "gretty" plugin (which I wrote) - it supports jetty 7/8/9 and servlet-api 2.5/3.0.1/3.1.0. Gretty plugin is available in maven central and on github: https://github.com/akhikhl/gretty . The documentation is also provided on github.

Upvotes: 0

Related Questions