Jump to: navigation, search

Difference between revisions of "Jetty/Tutorial/Embedding Jetty"

(New page: {{Jetty Tutorial | introduction = Jetty has a slogan "Don't deploy your application in Jetty, deploy Jetty in your application". What this means is that Jetty as an alternative to bundling...)
 
Line 7: Line 7:
  
 
| details =  
 
| details =  
=== The basics ===
 
 
To embed a Jetty server, the following steps are typical:
 
To embed a Jetty server, the following steps are typical:
 
# Create the server
 
# Create the server
Line 16: Line 15:
 
# wait (join the server to prevent main exiting).
 
# wait (join the server to prevent main exiting).
  
 +
== Servers and Handlers ==
 
=== Simplest Server ===  
 
=== Simplest Server ===  
 
The following code will instantiate and run the simplest possible Jetty server:
 
The following code will instantiate and run the simplest possible Jetty server:
Line 31: Line 31:
  
 
This runs a  
 
This runs a  
 +
 +
==
 +
 +
  
 
}}
 
}}

Revision as of 03:40, 27 July 2009



Introduction

Jetty has a slogan "Don't deploy your application in Jetty, deploy Jetty in your application". What this means is that Jetty as an alternative to bundling your application as a standard WAR to be deployed in Jetty, Jetty is designed to be a software component that can be instantiated and used in a java program just like any POJO.

This tutorial takes you step by step from the simplest jetty server instantiation, through programmatically, to running multiple web applications with standards based deployment descriptors.

The source for most of these examples is part of the standard jetty project.

Details

To embed a Jetty server, the following steps are typical:

  1. Create the server
  2. Add/Configure Connectors
  3. Add/Configure Handlers
  4. Add/Configure Servlets/Webapps to Handlers
  5. start the server
  6. wait (join the server to prevent main exiting).

Servers and Handlers

Simplest Server

The following code will instantiate and run the simplest possible Jetty server:

public class SimplestServer
{
    public static void main(String[] args)  throws Exception
    {
        Server server = new Server(8080);
        server.start();
        server.join();
    }
}

This runs a

==