try{
// Create the server
Server server = new Server();
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
SocketConnector connector = new SocketConnector();
String address = args[0];
int colon = address.lastIndexOf(':');
if (colon<0)
connector.setPort(Integer.parseInt(address));
else
{
connector.setHost(address.substring(0,colon));
connector.setPort(Integer.parseInt(address.substring(colon+1)));
}
server.setConnectors(new Connector[]{connector});
if (args.length<3)
{
ContextHandler context = new ContextHandler();
context.setContextPath(URIUtil.SLASH);
context.setResourceBase(args.length==1?".":args[1]);
ServletHandler servlet = new ServletHandler();
servlet.addServletWithMapping("org.mortbay.jetty.servlet.DefaultServlet", URIUtil.SLASH);
context.setHandler(servlet);
contexts.addHandler(context);
}
else if ("-webapps".equals(args[1]))
{
WebAppContext.addWebApplications(server, args[2], WebAppContext.WEB_DEFAULTS_XML, true, true);
}
else if ("-webapp".equals(args[1]))
{
WebAppContext webapp = new WebAppContext();
webapp.setResourceBase(args[2]);
webapp.setContextPath(URIUtil.SLASH);
contexts.addHandler(webapp);
}
server.start();