Search code examples
eclipsemavenjettym2eclipse

Terminating maven-jetty-plugin running in eclipse


I'm using maven-jetty-plugin to quickly run and debug WebApp I'm developing under Eclipse/m2eclipse. It starts ok and I can fully use the debugger, but I cannot stop the application gracefully.

When I do ctrl+c in the console view it just does nothing although in the launcher configuration "allocate console" is enabled.

In simple java projects the ctrl+c option works fine (tested on windows). So it seems like some remote/embedded jvm problem. My application uses persistent JMS queues, so after every restart I need to manually kill the session on the other server. This isn't very agile.

Anyone has an idea what's the source of the issue? Or maybe there is some known workaround for this?


Solution

  • If your using the m2eclipse plugin you can run maven directly from eclipse.

    1 Go to you debug configurations and under maven build create a new entry.
    2 Give it a name.
    3 Select the base directory of your maven project.
    4 for a goal enter jetty:run then click the debug button.

    All should be good. you can kill it from the console view inside of eclipse. All breakpoints should work as usual.

    To gracefully shutdown the application from eclipse you have to do the following. Add the following configuration to your pom for the jetty plugin. The important part here is the stop key and the stop port.

    <configuration>
        <tmpDir>target/not/necessary</tmpDir>
        <webAppConfig>
            <contextPath>/${project.name}</contextPath>
        </webAppConfig>
        <stopPort>9966</stopPort> 
        <stopKey>jetty-stop</stopKey>
    </configuration>
    

    Next add another run configuration for maven but this time set the goal to jetty:stop. It will perform a graceful shutdown.

    In order to make it more automatic: the goal can be set to jetty:stop jetty:start. In this way if the process is not running there will be a small warning but booting process will continue. Otherwise the other process will be gracefully shut down and then serwer will be started.

    Only one command is needed and it can be run by one shortcut (run last build) reducing context switching.