定制Jetty配置
尽管etc/jetty.xml设置了合理的缺省值,但为了满足你的实际需要,你仍然可以定制Jetty.Jetty的配置文件结构如下:
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure id="Server" name="code"><?xml version="1.0" encoding="ISO-8859-1"?><!--This is the document type descriptor for theorg.mortbay.XmlConfiguration class. It allows a java object to beconfigured by with a sequence of Set, Put and Call elements. These tags aremapped to methods on the object to be configured as follows: <Set name="Test">value</Set> == obj.setTest("value"); <Put name="Test">value</Put> == obj.put("Test","value"); <Call name="test"><Arg>value</Arg></Call> == obj.test("value");Values themselves may be configured objects that are created with the<New> tag or returned from a <Call> tag.Values are matched to arguments on a best effort approach, but typesmy be specified if a match is not achieved.$Id: configure_1_3.dtd,v 1.2 2005/10/26 20:48:48 gregwilkins Exp $--><!ENTITY % CONFIG "Set|Get|Put|Call|New|Ref|Array|Map|Property"><!ENTITY % VALUE "#PCDATA|Get|Call|New|Ref|Array|Map|SystemProperty|Property"><!ENTITY % TYPEATTR "type CDATA #IMPLIED " > <!-- String|Character|Short|Byte|Integer|Long|Boolean|Float|Double|char|short|byte|int|long|boolean|float|double|URL|InetAddress|InetAddrPort| #classname --><!ENTITY % IMPLIEDCLASSATTR "class NMTOKEN #IMPLIED" ><!ENTITY % CLASSATTR "class NMTOKEN #REQUIRED" ><!ENTITY % NAMEATTR "name NMTOKEN #REQUIRED" ><!ENTITY % DEFAULTATTR "default CDATA #IMPLIED" ><!ENTITY % IDATTR "id NMTOKEN #IMPLIED" ><!ENTITY % REQUIREDIDATTR "id NMTOKEN #REQUIRED" ><!--Configure Element.This is the root element that specifies the class of object thatcan be configured: <Configure name="test"> <Arg>value1</Arg> <Set name="Test">Value2</Set> </Call>This is equivalent to: Object o2 = o1.test("value1"); o2.setTest("value2");A Call with a class attribute is treated as a static call.--><!ELEMENT Call (Arg*,(%CONFIG;)*)><!ATTLIST Call %NAMEATTR; %IMPLIEDCLASSATTR; %IDATTR;><!--Arg Element.This element defines a positional argument for the Call element.The optional type attribute can force the type of the value.An Arg element can contain value text and/or value elements such as Call,New, SystemProperty, etc. If no value type is specified, then whitespace is trimmed out of the value. If it contains multiple valueelements they are added as strings before being converted to anyspecified type.--><!ELEMENT Arg ( %VALUE; )* ><!ATTLIST Arg %TYPEATTR; ><!--New Element.This element allows the creation of a new object as part of avalue for elements such as Set, Put, Arg, etc. The class attribute determinesthe type of the new object and the contained Arg elementsare used to select the constructor for the new object.A New element can contain a sequence of Arg elements followed bya sequence of elements such as Set, Put, Call, etc. elementswhich act on the new object: <New id="o" default="value" />This is equivalent to: System.getProperty("Test","value");--><!ELEMENT SystemProperty EMPTY><!ATTLIST SystemProperty %NAMEATTR; %DEFAULTATTR; %IDATTR;><!--Property Element.This element allows arbitrary properties to be retrieved by name.The name attribute specifies the property name and the optionaldefault argument provides a default value.A Property element can contain a sequence of elements such as Set, Put, Call, etc.which act on the retrieved object: <Property name="Server"> <Call id="jdbcIdMgr" name="getAttribute"> <Arg>jdbcIdMgr</Arg> </Call> </Property>--><!ELEMENT Property ((%CONFIG;)*)><!ATTLIST Property %NAMEATTR; %DEFAULTATTR; %IDATTR;>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"
<Configure id="Server" name="code"><Set name="connectors"> <Array type="org.mortbay.jetty.Connector"> <Item> <New /></Set> <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>... </New> </Item> </Array></Set>
<Set name="handlers"> <Array type="org.mortbay.jetty.Handler"> ...</Set>
<Set name="ThreadPool"> <New name="code"><Set name="UserRealms"><Array type="org.mortbay.jetty.security.UserRealm"> <Item> <New name="code"><?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure id="Server" default="."/>/webapps</Set> </New> </Arg> </Call></Configure>
java -jar start.jar etc/myjetty.xml
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure id="Server" /></Set> <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set> </New> </Arg> </Call> <Set name="handler"> <New id="Handlers" default="."/>/webapps</Set> <Set name="parentLoaderPriority">false</Set> <Set name="extract">true</Set> <Set name="allowDuplicates">false</Set> <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set> </New> </Arg> </Call></Configure>
java -jar start.jar etc/myjetty.xml
<Call name="addLifeCycle"> <Arg> <New default="."/>/contexts</Set> <Set name="scanInterval">5</Set> </New> </Arg> </Call>
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure id="Server" default="8080"/></Set> </New> </Arg> </Call> <Set name="handler"> <New id="ResourceHandler" name="code"><?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure id="Server" default="8080"/></Set> </New> </Arg> </Call> <Set name="handler"> <New id="Handlers" default="./logs"/>/request.log</Set> <Set name="append">false</Set></New> </Set> </Ref></Configure>