http://yinny.iteye.com/blog/1926799
First you have to download jetty http://dist.codehaus.org/jetty/
I'm under jetty-8.1.12.
In fact jetty the so-called installation process is to extract the downloaded files to the specified directory, and then according to different operating systems to configure the environment variables.
After decompression into D:\Program files\jetty-8.1.12
First, directory structure
As you can see from the diagram above, there are mainly several main directories
1, Bin directory
The directory of the startup script, also including the Start.jar under the root path, is used primarily to boot, to boot the resource load and to start the service.
2, etc directory
The directory of the configuration file, also includes the Start.ini under the root path, which is used to guide the loading sequence of the Start.jar and the loading module, which is followed by a detailed explanation.
3, Lib Directory
Library file directory, if you need to debug jetty, you can download the source code added to eclipse, the client remote debugging can, command: java-xrunjdwp:transport=dt_socket,server=y,suspend=y,address =8090-deos_debug=true-jar Start.jar
4, WebApps Directory
Application deployment directory, similar to Tomcat WebApps directory
Second, the configuration file
1, Start.ini
Guide the configuration files and order that jetty need to load when starting
The order of these profiles cannot be incorrect, such as if placing jetty-deploy.xml at the bottom will cause Jetty-webapps to fail to initialize. Briefly describe the role of the next few configurations:
1) jmx.xml
By removing the annotation, some classes in the container can be managed at run time, such as if the project needs to reread a configuration file without rebooting, either by means of semaphores or by JMX. This is because the function manages the classes that need to be managed in the project, so it is placed at the top.
2) Jetty.xml
This does not explain, the configuration file corresponds to the server class, the management of Connection,thread Pool,handler and so on.
3) Deploy.xml
This configuration file corresponds to the deployservice described in the previous blog, in Jetty is Deploymanager, Deployment Manager, so if this thing is in the wrong place, the following Webapps.xml natural error.
4) Webapps.xml
The Webappcontext of the war package makes it easy to build on it.
5) Contexts.xml
Another type of deployer, primarily reading the XML file in the deployment directory, skips over where it is used.
2, Jetty.xml
You can see that the default IO for Nio,hanler is the core approach in the server, contexts is a collection of webappcontext, and when the request comes in, contexts is responsible for distributing the request to the specific app and DefaultHandler return 404 error page, in fact from this handlers can be seen, the request will be once through this handler, once the Hanlder is submitted to quit, Until not be handler walk to the DefaultHandler inside return 404 of the page. In fact, the custom handler loads the head of the handlers to handle some static resource access, thus bypassing the access of the application Webappcontext and speeding up the processing speed of the static resources. Eg:rerourcehandler.
3, Deploy.xml
Call the Addbean method, Ref = Contexts is the contexthandlercollection that is already new in the above server, holding the contexts is designed to register all the apps produced by the class ( i.e. Webappcontexthandler).
4, Webapps.xml
Third, start:
1, through the cmd command to start
Start jetty command: Java-jar Start.jar
Start.jar The following is the argument passed to Start.jar, with multiple arguments separated by spaces.
Parameter content can have the following:
--help View Help information
--stop Stop the service, the next section will talk about
--version View current Jetty version information
Other: As Jetty service profile
We see the previous command specifying the parameter content as Etc/jetty.xml, which actually points to a service profile that is used to set up the system configuration information for the jetty service startup. such as listening ports, publishing Web applications under a directory, Jndi configuration, and so on, are described in detail in subsequent chapters. Of course, the service profile can be multiple, such as:
Java-jar Start.jar Etc/jetty.xml Etc/jetty-plus.xml
This command specifies two service profiles, Etc/jetty.xml and Etc/jetty-plus.xml.
In subsequent chapters, the term "service profile" refers to these files.
Using the browser to open the address http://localhost:8080/, you will see the default example site for jetty.
If you can access http://localhost:8080 instructions jetty start successfully.
2. Stop Service
Hold the CTRL-C key in the terminal window where you just started jetty.
But you can start this way.
Java-dstop. Port=8009-dstop. Key=secret-jar Start.jar
The jetty will listen to port 8009 you specify locally and will verify the password secret the next time the command is closed. Now again by command:
Java-dstop. Port=8009-dstop. Key=secret-jar Start.jar--stop
You can stop the jetty service in another terminal window on this machine. In a Linux system, you can move the jetty process to the background and then stop the jetty service through the command line.
Oh, look at the above introduction you may think that jetty start and shutdown is so troublesome, not at all in line with jetty exquisite temperament. In fact, jetty for us to prepare the various operating systems in a quick way. But remember that no matter what the way is ultimately through the Start.jar to start the jetty service.
3, Embedded launch
Jetty Installation
To create the jetty service:
Server is the core class of jetty, running this class can start the jetty service, Access service address: http://localhost:8080/
Although the service starts normally, but does not join any handle in the service, the visit will return 404 error.
As shown in figure
Create Handler
Jetty is oriented toward the handler architecture, just as spring is oriented to the bean schema, ibatis to the statement architecture.
Add the custom Hellohandler to the server as follows:
Re-execute this class, Access service address: http://localhost:8080/, the access effect is as follows:
Four, Start.jar loading principle
The main method is very simple, and a method is executed
The ParseCommandLine method mainly does two things, namely:
1. Parse command line parameters
2, locate load resources and invoke the corresponding class size according to the profile reflection: 63.1 KB Size: 100.5 KB size: 34.6 KB size: 103.6 KB size: 31.6 KB size: 48.7 KB size: 16.9 KB size: 70.3 KB Size: 12.9 KB size: 29.3 KB size: 13.5 KB size: 24.5 KB size: 50.7 KB size: 27.5 KB size: 29.8 KB size: 12.9 KB