The Jetty J2EE webcontainer represents a highly modularized server application. Because of that you are able to start the web server directly in Java code. For example that allows developers to deploy Servlets, JSP pages and WAR files within JUnit tests or use the webcontainer directly for other issues. The following example shows basically how to start and configure Jetty.
package org.developers.blog.jetty.embedded;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
public class JettyExample {
public static void main(String[] args) throws Exception {
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
connector.setHost("127.0.0.1");
server.addConnector(connector);
WebAppContext wac = new WebAppContext();
wac.setContextPath("/");
//expanded war or path of war file
wac.setWar("./src/main/resources/web");
server.addHandler(wac);
server.setStopAtShutdown(true);
//another way is to use an external jetty configuration file
//XmlConfiguration configuration =
//new XmlConfiguration(new File("/path/jetty-config.xml").toURL());
//configuration.configure(server);
server.start();
}
}
Best regards
Rafael Sobek
Technorati Tags: jetty embedded jetty

How to embedd Jetty Server
groovy How to embedd Jetty