/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.maven;
//~--- non-JDK imports --------------------------------------------------------
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
/**
*
* @author Sebastian Sdorra
*/
public class WebServer extends Thread
{
/** Field description */
public static final String CONTEXTPATH = "/sample";
/** Field description */
public static final int PORT = 8989;
/** Field description */
public static final String WAR = File.separator + "webapp" + File.separator
+ "sample.war";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public WebServer()
{
String baseDir = System.getProperty("basedir", ".");
Connector connector = new SelectChannelConnector();
connector.setPort(PORT);
server.addConnector(connector);
WebAppContext wac = new WebAppContext();
wac.setContextPath(CONTEXTPATH);
wac.setWar(baseDir + WAR);
wac.setExtractWAR(false);
server.setHandler(wac);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
public void run()
{
try
{
server.start();
server.join();
}
catch (Exception ex)
{
throw new RuntimeException(ex);
}
}
/**
* Method description
*
*/
public void stopServer()
{
try
{
server.setStopAtShutdown(true);
}
catch (Exception ex)
{
ex.printStackTrace(System.err);
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Server server = new Server();
}