416453 Add comments to embedded FileServer example
This commit is contained in:
parent
b4a8871b62
commit
36efbb9869
|
@ -32,17 +32,27 @@ public class FileServer
|
|||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
// Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0
|
||||
// then a randomly available port will be assigned that you can either look in the logs for the port,
|
||||
// or programmatically obtain it for use in test cases.
|
||||
Server server = new Server(8080);
|
||||
|
||||
// Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is
|
||||
// a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples.
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
// Configure the ResourceHandler. Setting the resource base indicates where the files should be served out of.
|
||||
// In this example it is the current directory but it can be configured to anything that the jvm has access to.
|
||||
resource_handler.setDirectoriesListed(true);
|
||||
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
|
||||
resource_handler.setResourceBase(".");
|
||||
|
||||
|
||||
// Add the ResourceHandler to the server.
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
|
||||
//Start things up! By using the server.join() the server thread will join with the current thread.
|
||||
// See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue