1
//========================================================================
2
//$Id: JettyStopMojo.java 5222 2009-05-29 07:34:32Z dyu $
3
//Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
4
//------------------------------------------------------------------------
5
//Licensed under the Apache License, Version 2.0 (the "License");
6
//you may not use this file except in compliance with the License.
7
//You may obtain a copy of the License at
8
//http://www.apache.org/licenses/LICENSE-2.0
9
//Unless required by applicable law or agreed to in writing, software
10
//distributed under the License is distributed on an "AS IS" BASIS,
11
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//See the License for the specific language governing permissions and
13
//limitations under the License.
14
//========================================================================
16
package org.mortbay.jetty.plugin;
18
import java.io.OutputStream;
19
import java.net.ConnectException;
20
import java.net.InetAddress;
21
import java.net.Socket;
23
import org.apache.maven.plugin.AbstractMojo;
24
import org.apache.maven.plugin.MojoExecutionException;
25
import org.apache.maven.plugin.MojoFailureException;
28
* JettyStopMojo - stops a running instance of jetty.
29
* The ff are required:
36
* @description Stops jetty that is configured with <stopKey> and <stopPort>.
39
public class JettyStopMojo extends AbstractMojo
43
* Port to listen to stop jetty on sending stop command
47
protected int stopPort;
50
* Key to provide when stopping jetty on executing java -DSTOP.KEY=<stopKey>
51
* -DSTOP.PORT=<stopPort> -jar start.jar --stop
55
protected String stopKey;
57
public void execute() throws MojoExecutionException, MojoFailureException
60
throw new MojoExecutionException("Please specify a valid port");
62
throw new MojoExecutionException("Please specify a valid stopKey");
66
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),stopPort);
67
s.setSoLinger(false, 0);
69
OutputStream out=s.getOutputStream();
70
out.write((stopKey+"\r\nstop\r\n").getBytes());
74
catch (ConnectException e)
76
getLog().info("Jetty not running!");