I searched quite a bit on
lazyweb but couldn't find anything conclusive so.. for posterity, here is how to start an
embedded Jetty (a lightweight Java
Servlet container/webserver) without any XML, add
<init-param/>
values without XML (
Wicket's
WicketFilter
requires a
applicationClassName
init-param
that contains the fully qualified class name of your
WebApplication
) and with
Wicket:
import org.apache.wicket.protocol.http.ContextParamWebApplicationFactory; import org.apache.wicket.protocol.http.WicketFilter; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.DefaultServlet; import org.mortbay.jetty.servlet.FilterHolder;
public class EmbeddedJettyWithWicket { // change these accordingly: private static final String LISTEN_HOST = "localhost"; private static final int LISTEN_PORT = 8888; private static final String WICKET_WEBAPP_CLASS_NAME = MyWebApp.class.getName();
public static final void main(String[] args) throws Exception { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setHost(LISTEN_HOST); connector.setPort(LISTEN_PORT); server.setConnectors(new Connector[] { connector }); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(DefaultServlet.class, "/*"); FilterHolder filterHolder = new FilterHolder(WicketFilter.class); filterHolder.setInitParameter(ContextParamWebApplicationFactory.APP_CLASS_PARAM, WICKET_WEBAPP_CLASS_NAME); root.addFilter(filterHolder, "/*", 1); server.start(); server.join(); } } |
Java2html |
UPDATE: replaced with code that actually works
Labels: java, jetty, wicket
0 Comments:
Post a Comment
<< Home