Gradle embedded jetty plugin is not stopping automatically

I am able to run embedded jetty with gradle jettyRunWar command. However, it is not automatically stopped on program termination.

I tried below two code after searching the solution on stackoverflow and other forums. But none works.

1) build.gradle

apply plugin: 'jetty'

task runJetty() {

    jettyStop.stopPort = 8090

    dependsOn jettyRunWar
    finalizedBy jettyStop
}

2) build.gradle

apply plugin: 'jetty'

task runJetty() {

    doFirst {
        jettyRunWar.stopPort = 8090
        jettyRunWar.stopKey = 'stopKey'

        jettyRunWar.daemon = true
        tasks.jettyRunWar.execute()
    }

    doLast {
        jettyStop.stopPort = 8090
        jettyStop.stopKey = 'stopKey'

        tasks.jettyStop.execute()
    }
}

In both cases, on running runJetty task, embedded jetty server starts but did not stop on program termination.

FWIW: I am using Eclipse External Tools Configuration to start and terminate build.gradle. And, using 8080 port in the url to test.

Answers


In 2) try setting the stopPort to something else, such as 8090.

I think you are actually running jetty on 8080 so that port will be occupied and you are unable to set up a 'stop' listener.

Otherwise you can just put the following in your build.gradle

// need to set the stopPort and stopKey so we are able to stop jetty!
jettyRunWar.stopPort = 8090
jettyRunWar.stopKey = 'stopKey'
jettyStop.stopPort = 8090
jettyStop.stopKey = 'stopKey'

Here is an example that worked for me in intelliJ http://pastebin.com/eTtvCdTb

I run 'jettyRunWar' and 'jettyStop' from the Gradle tasks panel in intelliJ. I've only set the parameters up for jettyRun just in case I run that task by accident, I can then shut the server down.


Need Your Help

How can i restrict access to the files of my website?

asp.net security iis custom-pages

How can i prevent users from getting the list of files that exist in my website?

WPF Adding a custom property in a control

c# wpf xaml properties custom-controls

Ok i have a WPF application in which i have a resource dictionary. In the dictionary i have a new style for a Button that looks like this :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.