Installation and configuration of Jetty

Source: Internet
Author: User
Tags java web

This paper originates from http://book.51cto.com/art/200808/86012.htm

one. Download and installation of Jetty

Jetty is another outstanding Web server in the Java domain, and this server is also an Open-source project. Compared to Tomcat, Jetty has a greater advantage as an embedded server, that is, if you add a Jetty jar file to your application, the application can provide WEB services externally in your code.

The following describes the download, installation, and basic configuration of Jetty.

two. Download and installation of Jetty

Jetty is also a platform-independent Java WEB server that can run on a Windows platform or on a Linux platform, download and install Jetty as follows.

(1) Login to HTTP://JETTY.MORTBAY.COMLJETTY/INDEX.HTM1 site, download the latest version of jetty. When I was in the book, the latest version of Jetty is Jetty-6.0.0rco, download Jetty-6.0.0rco and P file, which is a platform-independent compression package that can be used either by Windows or Linux.

(2) to extract the Jetty-6.0.orco.zip file, the following file structure should be obtained.

ETC: This path is used to store jetty configuration files.

Examples: This path is used to store examples of jetty.

Legal: This path is used to store the lisence information for the project.

LIB: This path is used to store the J-cylinder files required to run jetty.

Modules: This path is used to store jetty modules, including API documentation.

Patches: contains some patch instructions.

POM.XM1: Is the jetty build file, which is not an ant build file, but a Mavaen2 build file.

Project-site: A required style file that contains a jetty Web site.

Readme.txt: Contains the most basic usage information.

Start.jar: Launches the jetty boot file.

A simple version of the Version.txt:Jetty version update log.

WebApps: This path is used to store automatically deployed Web applications, and Web applications are automatically deployed whenever a user's web application is replicated to that path.

Webapps-plus: Store Web applications that demonstrate Jetty extended properties, and Web applications under that path can be deployed automatically.

(3) The uncompressed file can be placed on any path. To run Jetty you need to use the following command:

Java-jar Start.jar

It is recommended to write the above command as a script, such as a batch processing command under Windows, and a shell script under Linux. Each time you run its script file directly.

After a successful run, start the browser and enter http://localhost:8080/in the Address bar, and then return to the interface shown in Figure 1.14, which means that the Jetty installation was successful

498) this.style.width=498; "Border=0>
Figure 1.14Jetty Installation Successful interface

three. Basic configuration of Jetty (1)

The basic configuration of Jetty is similar to Tomcat, where the port settings for Jetty and how to deploy Web applications are mainly described. Because Jetty is an embedded WEB server, it is very special to set up.

The Jetty configuration file is placed under the ETC path, and there are several profiles under that path:

JETTY.XM1 files.

JETTY-JMX.XM1 files.

JETTY-PLUS.XM1 files.

WEBDEFAULT.XM1 files.

Where the Webdefault.xm1 file is the default profile for Web applications, there is not much to do with the configuration of the Jetty, which usually does not need to be modified.

The other three are Tomcat profiles: The Jetty.xm1 file is the default profile; Jetty-jmx.xm1 is the configuration file that starts the JMX control; The Jetty-plus.xm1 file is a configuration file that increases the jetty extension functionality. Enter the following command when you start Jetty:

Java-jar Startup.jar
When you use the Jetty.xm1 file by default, you start the jetty, which is the same effect as the following command:
Java-jar Startup.jar Etc/jetty.xml
You can also specify multiple profiles at startup, and you can enter the following command:
Java-jar Startup.jaretc/jetty. NL etc/jetty-plus.xml

Open the Jetty configuration file, the root element of the profile is configure, and you will see the following matching
The element is placed.

Set: equivalent to calling SE only xx method.

Get: The equivalent of calling the GetXXX method.

New: Creates an instance of a class.

ARG: Passing parameters to a method or constructor.

Array: sets an array.

Item: Sets the-j page of an array or collection.

Call: Invokes a method.

Jetty is an embedded Web container, so its service corresponds to a Server instance, and you can see the following fragment in the configuration file:

<1-configured a jetty server process one
<configure id= "Server" class= "Org.mortbay.jetty.Server" >

1. Configure the Jetty service port

Configure the various child elements in the element, that is, the operation of the instance of the server. Under the Configure element, the set child element is shown in the following code, the Name property of the set child element is connectors, and the effect is equivalent to calling the Setconnectors method to set the Web service's provisioning port. The method requires an array of connector that contains the array child elements that are used to set the parameter of the method. The item child element in the array element is the data item for the array, and each connector corresponds to a connection provider.

< ' a similar to calling Setconnectors method-->
<setname= "Co Kou ectorsll>
<! a setconnectors method to pass in the parameter ><array type= "Org.mortbay.jetty.Connector" >
<!--The following connector provides common Web services
-->
〈itern>
<newclass= "ORG.MORTBAY.JETTY.N Industrial O.selectchannelconnector" >
<set name= "Port" >8080</Set>
<set ame= "max work Dletime" >30000</Set>
<set name= "Lowresourcemaxidletime" >3000</set><set name= "acceptors" >l</Set>
</new><litem><! if the Java NI. is not available, use the following connector-→
<!--
<item><newclass= "org.mortbay.jetty.b Industrial O.socketconnector" >
<set Port Ame= "Port" >8081</Set>
<set name= "MaxIdleTime" >50000</Set></New>
<Itern>
-->
<!--Use this connector for few very active connectionsonly f
Selectchannelconnector cannot handle your load
〈itern>
<new class= "Org.mortbay.jetty.nio.BlockingChannelConnector" >
<set name= "Port" >8083</set><set name= "MaxIdleTime" >30000</Set>
<set name= "Lowresourcemaxidletime" >3000</Set></New><lItem>
-->
<!--The following connector service provider port for setting up HTTPS
<!--
〈itern>
<new class= "Org.rnortbay.jetty.security.SslSocketConnector" >
<set narne= "Port" >8443</Set>
<set narne= "Rnaxidletirne" >30000</Set>
<set narne= "Keystore" ><systernproperty narne= "Jetty.horne" default= "."
1>/etc/keystore</set>
<set narne= "Password" >OBF:lvnylzlolx8elvnwlvn61x8g1zlulvn4<1Set>
<set narne= "Keypassword" >OBF:lu2ulwmllz7s1z7alwnllu2g</Set>
</New>
<i worker Tern>
-->
</Array>
</Set>

In the configuration fragment above, the default first connector is valid, and the connector is the connector of the regular Web service, where 8080 is the jetty default port.

The author will revise the fragment as follows:

<!--The following connector provides common Web services
>
〈itern>
<!--provides connector--> based on NIO
<new class= "Org.rnortbay.jetty.nio.SelectChannelConnector" >
<!... Set port number One
<set narne= "Port" >8886</set><setnarne= "Rnaxidlet worker Rne" >30000</Set>
<setnarne= "Lowresourcemax Industrial Dletirne" >3000</Set>
<set narne= "acceptors" >l</Set>
</New><lItem>

After being modified to the sample shown above, the Jetty service port is 88860, which is also the port used by the author.

2. Deploying Web Applications

Jetty also supports automatic deployment and configuration file deployment.

If you start with the default configuration file, WebApps automatically deploys the directory. That is, all Web applications stored in the WebApps path are automatically deployed in the Jetty container.

If you start with the jetty extension, ~p add jetty-plus.xrnl files to boot, Webapps-plus automatically deploys the directory and automatically deploys all Web applications placed on that path to the jetty container. Here's how to use a configuration file to deploy a Web application.

Deploying a Web application requires the use of or Roar g.mortba. Button T is ty.we to the pp.we by Bappco∞nt Superior ex Liu T, an instance of this class corresponds to a WEB application, and the class also contains multiple static overloaded methods: Addwebapplications. This method is used to deploy multiple Web applications at the same time, which is used to configure an automatic deployment directory.

The fragment of the JETTY.XRNL configuration file is as follows:

<!--static method to invoke Webappcontext addwebapplications-->
<call class= "Org.rnortbay.jetty.webapp.WebAppContext"
Name= "Addwebapplications" >
<1 one of the following is used to pass parameters to the method-->
<arg><ref id= "Contexts" i></arg>
< ' A designated automatic deployment directory one '
<Arg>./webapps</Arg>
<!--Configure the default profile for Web applications-->
<arg><systemproperty name= "Jetty.home" default= "." />
/etc/webdefault. Knife nl</arg>
<!--whether to decompress >
<arg type= "Boolean" >True</Arg>
<arg type= "Boolean" >False</Arg>
</Call>
The fragment of the Jetty-plus.xml file is as follows:
<! a static method that invokes Webappcontext addwebapplications-->
<call class= "Org.mortbay.jetty.webapp.WebAppContext"
Name= "Addwebapplications" >
<!-is used to pass parameters to a method->
<arg><ref id= "Server"/></arg>
< ' a specified automatic deployment directory-->
<Arg>./webapps-plus</Arg>
<! a default profile for configuring Web applications One
<Arg>org/mortbay/jetty/webapp/webdefault.xml</Arg>
<arg><ref id= "Plusconfig"/></arg>
< ' one decompression >
<arg type= "boolean" >true</arg><arg type= "boolean" >False</Arg>
</Call>

By looking at the profile, you can add an automatic deployment path to a Web application after each call to the Addwebapplications method. If necessary, users can fully increase their own automated deployment path, and if an automatic deployment path is added, all Web applications under that path will be automatically deployed.

If you need to deploy only one Web application, there are two ways to do this:

• Modify the Jetty.xml file.
• Add your own configuration files.

As described earlier, you should try to avoid modifying the default configuration file for Web servers. If the reader really needs to deploy the Web application by modifying the Jetty.xml file, add the following fragment under the Jetty Configure element:

<!--Create a Web application one
<new class= "Org.mortbay.jetty.webapp.WebAppContext" ><!... Three construction parameters ...
<arg><ref id= "Contexts"/></arg><!--set the document path for the Web application-->
<Arg>G:/StrutsTest/js</Arg><!... Set up url--> for Web applications
<Arg>/</Arg>
<!--Set the default configuration descriptor for Web applications one
<set name= "Defaultsdescriptor" >
<systemproperty name= "Jetty.home" default= "." />/etc/webdefault. Knife nl</set>
<!-is equivalent to calling the Setvirtualhosts method to set up a virtual host->
<set name= "virtualhosts" ><!--array representation create an array one
<array type= "Java.lang.String" >
<Item>localhost</Item>
</Array>
</Set>
<! a similar to calling Getsessionhandler method one
<get name= "Sessionhandler" >
<set name= "SessionManager" >
<new class= "Org.mortbay.jetty.servlet.HashSessionManager" >
< ' a set sess on the super time length->
<setname= "Maxinact nterval" type= "work Port T" >600</Set>
</New>
</Set></Get></New>

Note: The code fragment is only annotated in the Jetty.xml file, as long as the code fragment annotation is canceled. Note, however, that the Jetty.xml file has a small error by default, and its Name property value of the set element with a straight timeout is maxinactivelntervale. Actually Hashsessi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.