Thursday, July 15, 2010

On the open source Jetty Servlet Container



Jetty is a Java language using the open source servlet container, it is Java-based web content such as JSP and servlet to provide operating environment. Jetty servlet container as an optional feature is an additional, but it really is because it is known as a can be embedded into other Java code in the servlet container designed. This means that Jetty development team will provide as a set of Jar files out, so you can code your own will into an object instance of the servlet container and can manipulate the container object.

Jetty servlet container in not really a new face, it has emerged from 1998. Jetty is released under the Apache 2.0 open source protocol, you can free software and commercial software to use Jetty.

MyEclipse 6.5 below describes the whole process to use jetty.

Environment: Windows XP + JDK 1.6.11 + MyEclipse 6.5 + jetty-7.0.0pre3

1. Open myEclipse, new java project Jetty, and logs build webapps folder (and src at the same level), established under the src config, servlet and test folder in the webapps directory to establish manage the work as a web directory.

2. Will be $ (ROOT) jetty-7.0.0pre3lib three jar packages under the accession project classpath, the $ (Root): jetty-7.0.0pre3libjsp-2.1 of the four-jar package to join the project classpath, copy $ ( ROOT) jetty-7.0.0pre3etc under jetty.xml, webdefault.xml and realm.properties to srcconfig, the same copy $ (ROOT) jetty-7.0.0pre3contexts under the under the test.xml to srcconfig and renamed manage.xml.

3. Modify jetty.xml, manage.xml, these configuration files with jetty.xml, webdefault.xml and realm.properties path to srcconfig, and in the webapps / manage under the new index.jsp.

4. In the test directory under the new Start.java, the code is as follows:



1 import org.mortbay.jetty .*;
2
3 import java.io. *;
4
5 import org.mortbay.jetty.handler .*;
6
7 import org.mortbay.xml .*;
8
9 public class start (
10
11 public static void main (String args []) (
12
13 Server server = new Server (8080);
14
15 server.setHandler (new DefaultHandler ());
16
17 XmlConfiguration cfg = null;
18
19 try (
20
21 cfg = new XmlConfiguration (new FileInputStream (". / Src / com / greysh / config / jetty.xml"));
22
23 cfg.configure (server);
24
25 server.start ();
26
27 System.out.println ("Jetty Started ...");
28
29) catch (FileNotFoundException e) (
30
31 e.printStackTrace ();
32
33)
34
35 catch (IOException e) (
36
37 e.printStackTrace ();
38
39) catch (Exception e) (
40
41 e.printStackTrace ();
42
43)
44
45)
46
47) run the Start class, using IE to access http://localhost:8080/, click / manage ---> org.mortbay.jetty.webapp.WebAppContext @ 1275d39 (/ manage, file: / D: / Program% 20Files / MyEclipse% 206.5/workspace/Jetty/webapps/manage /), then you can successfully run the Jetty.
If you want to run in the Jetty servlet, operation is as follows: