views:

189

answers:

0

Hi, I'd like to have the same Jetty server configuration, created programatically.

When I run mvn jetty:run-exploded, my app works fine. When I run it from my code, the static content is not loaded. I know that I have to add a static content Servlet, so I tried:

Server server = new Server(8080);
Context ctx = new Context( server, "/", Context.SESSIONS );

DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder defaultSH = new ServletHolder( defaultServlet );
defaultSH.setInitParameter( "resourceBase", "./");
ctx.addServlet( defaultSH, "/img" );
ctx.addServlet( defaultSH, "/css" );
ctx.addServlet( defaultSH, "/js" );

I am assuming that the pwd is in the webapp's "root", i.e. where the WEB-INF dir is. This does not work.

Anyway. Is somewhere a clean block of pure Java code which will give me the exact same server config as the mvn jetty:run-explodeds default?

Thanks for help, Ondra