It is often overlooked that
Jetty can be used as an embedded web+servlet container to any java application. It was recently asked on the
Jetty Mailing list as to why you would want to do as this as well as how you would do this. David Yu stepped up to the plate and offered up a simple code snippet for illustrating the how part:
Server server = new Server();
Connector connector=new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/foo");
webappcontext.setWar("C:/path/to/your/folder");
server.setHandler(webappcontext);
server.start();
server.join();
As for the why part, that all depends on your application. If you had a desktop application you could offer a help based system that was authored in HTML and simply give your users an embedded browser to view this data, allowing you to easily update the content without recompiling the code. Another application is very similar to how Google operates some of its desktop applications. Instead of popping up a dialogue window, you could pop-open a browser and have the user fill in their settings there.
tags: java jetty
links: digg this del.icio.us technorati