aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-09-18 10:58:34 (EDT)
committerThomas Becker2013-09-19 05:33:05 (EDT)
commit317f4b7de186ff6546f281615dae6a8e9ba6ca54 (patch)
treee2346077f9329fe4d240911eca84db850eca98e6
parent1394559e00a05d65404e40c9ec2baafc7af17698 (diff)
downloadorg.eclipse.jetty.project-317f4b7de186ff6546f281615dae6a8e9ba6ca54.zip
org.eclipse.jetty.project-317f4b7de186ff6546f281615dae6a8e9ba6ca54.tar.gz
org.eclipse.jetty.project-317f4b7de186ff6546f281615dae6a8e9ba6ca54.tar.bz2
416453 Add comments to embedded FileServer example
-rw-r--r--examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java
index 15d947a..f47b666 100644
--- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java
@@ -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();
}