I have a scalatra server with Jetty embedded and the initialization code for the two is listed below, where HelloServlet
is the main servlet to be loaded.
Is there a way I can set this servlet at build or runtime?
I prefer not to use XMLs for configuring as I would like these methods to add other hooks there (unless one can use both?)
Jetty Startup
public class ExampleServer {
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/hello");
context.addServlet(HelloServlet.class, "/"); // Can this be defined later??
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
}
}
Scalatra Startup
class ScalatraBootstrap extends LifeCycle {
override def init(context: ServletContext) {
context.mount(new HelloServlet, "/*") // Can this be defined later??
}
}