一 簡介
挂在eclipse基金會下
java語言編寫的實作servlet規範的web容器
支援SPDY, WebSocket, OSGi, JMX, JNDI, JAAS
最新版本是jetty9,必須JDK7支援
目前使用的項目:alibaba japan,b2b activeMq,apache-camel,fisheye,confluence,hadoop (更全可見:http://www.eclipse.org/jetty/powered/)
源碼存放位址:https://github.com/eclipse/jetty.project
ps:
挂在eclipse基金會下其他知名開源架構還有 Sphinx(搜尋伺服器)Hudson(持續內建),Subversive(svn工具),AspectJ(aop架構),hadoop(離線計算)等
二 主要目錄結構解析
bin/ — 啟動、停止腳本
etc/ — 配置檔案目錄,不同于tomcat的conf
lib/ — 自身必須加裝的包 例如jetty-deploy,jetty-http,jetty-io 等
license-eplv10-aslv20.html
logs/ — 日志目錄
notice.html
README.txt
resources/ — jetty的資源檔案 ,裡面是一些log4j的配置
start.d/
start.ini
start.jar — jetty 的啟動jar包 s示例:java $JAVA_OPTS -Djetty.port=$app_port -jar start.jar $jetty_etc/jetty.xml
VERSION.txt
webapps/ — 包的部署目錄
webapps.demo/
三 幾個重要的配置檔案
3.1 START.INI
當你通過:java -jar start.jar 啟動時候,讀取的配置來之 $JETTY_HOME/start.ini
具體檢視目前使用的配置 通過指令 java -jar start.jar –help 以下就是預設配置
——————————————————————————————-
The current start.ini arguments are:
OPTIONS=Server,websocket,resources,ext
threads.min=10
threads.max=200
threads.timeout=60000
jetty.dump.start=false
jetty.dump.stop=false
etc/jetty.xml
OPTIONS=jmx
etc/jetty-jmx.xml
OPTIONS=jsp
jetty.port=8080
http.timeout=30000
etc/jetty-http.xml
etc/jetty-deploy.xml
OPTIONS=rewrite
etc/jetty-rewrite.xml
etc/jetty-demo.xml
OPTIONS=client
etc/test-realm.xml
OPTIONS=jaas
jaas.login.conf=webapps.demo/test-jaas.d/login.conf
etc/jetty-jaas.xml
OPTIONS=jndi,jndi.demo
OPTIONS=plus
etc/jetty-plus.xml
OPTIONS=annotations
etc/jetty-annotations.xml
etc/jetty-ssl.xml
etc/jetty-https.xml
etc/jetty-demo.xml 中定義了預設啟動加載的應用包 在webapps.demo目錄 root路徑的加載是在ROOT包下
———————————————
<Ref refid=”DeploymentManager”>
<Call id=”webappprovider” name=”addAppProvider”>
<Arg>
<New class=”org.eclipse.jetty.deploy.providers.WebAppProvider”>
<Set name=”monitoredDirName”><Property name=”jetty.home” default=”.” />/webapps.demo</Set>
<Set name=”defaultsDescriptor”><Property name=”jetty.home” default=”.” />/etc/webdefault.xml</Set>
另外jetty啟動的JVM參數配置也在這裡 vim start.ini
#===========================================================
# Configure JVM arguments.
# If JVM args are include in an ini file then –exec is needed
# to start a new JVM from start.jar with the extra args.
# If you wish to avoid an extra JVM running, place JVM args
# on the normal command line and do not use –exec
#———————————————————–
# –exec
# -Xmx2000m
# -Xmn512m
# -XX:+UseConcMarkSweepGC
# -XX:ParallelCMSThreads=2
# -XX:+CMSClassUnloadingEnabled
# -XX:+UseCMSCompactAtFullCollection
# -XX:CMSInitiatingOccupancyFraction=80
3.2 JETTY.XML
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- jetty 的每一示例都是一個Server -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- 請求的線程池配置-->
<Get name="ThreadPool">
<Set name="minThreads" type="int"><Property name="threads.min" default="10"/></Set>
<Set name="maxThreads" type="int"><Property name="threads.max" default="200"/></Set>
<Set name="idleTimeout" type="int"><Property name="threads.timeout" default="60000"/></Set>
<Set name="detailedDump">false</Set>
</Get>
<!-- 線程的排程器 -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
</Arg>
</Call>
<!-- http https SPDY請求進來的預設配置 -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">false</Set>
<Set name="headerCacheSize">512</Set>
<!-- Uncomment to enable handling of X-Forwarded- style headers
<Call name="addCustomizer">
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
-->
</New>
<!-- 請求的處理器,會處理Contexts中定義的handler 及預設的Handler-->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Array>
</Set>
<!-- 其他配置選項 -->
<Set name="stopAtShutdown">true</Set>
<Set name="stopTimeout">5000</Set>
<Set name="dumpAfterStart"><Property name="jetty.dump.start" default="false"/></Set>
<Set name="dumpBeforeStop"><Property name="jetty.dump.stop" default="false"/></Set>
</Configure>
3.3 ETC/JETTY-DEPLOY.XML
定義了 應用加載包的資訊
———————————————————————————————————-
<?xml version=”1.0″?>
<!DOCTYPE Configure PUBLIC “-//Jetty//Configure//EN” “http://www.eclipse.org/jetty/configure_9_0.dtd”>
<!– 定義包的部署管理 –>
<Configure id=”Server” class=”org.eclipse.jetty.server.Server”>
<Call name=”addBean”>
<New id=”DeploymentManager” class=”org.eclipse.jetty.deploy.DeploymentManager”>
<!– 加載的上下文目錄 Contexts 的定義是在 jetty.xml中 –>
<Set name=”contexts”>
<Ref refid=”Contexts” />
</Set>
<Call name=”setContextAttribute”>
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
<Arg>.*/servlet-api-[^/]*\.jar$</Arg>
</Call>
<!– 應用的 provider 預設指向的是deploy目錄 加載的配置是:/etc/webdefault.xml –>
<Set name=”monitoredDirName”><Property name=”jetty.home” default=”.” />/webapps</Set>
<Set name=”scanInterval”>1</Set>
<Set name=”extractWars”>true</Set>
<Set name=”configurationManager”>
<New class=”org.eclipse.jetty.deploy.PropertiesConfigurationManager”>
<!– file of context configuration properties
<Set name=”file”><SystemProperty name=”jetty.home”/>/etc/some.properties</Set>
–>
<!– set a context configuration property
<Call name=”put”><Arg>name</Arg><Arg>value</Arg></Call>
</New>
</Arg>
自己定義個加載目錄
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://jetty.mortbay.org/configure.dtd”>
<Configure class=”org.mortbay.jetty.webapp.WebAppContext”>
<Set name=”contextPath”>/</Set>
<Set name=”war”>/home/xx/xx.war</Set>
<Set name=”extractWAR”>true</Set>
<Set name=”copyWebDir”>false</Set>
若是WAR是myapp.war,那麼通路路徑就是/myapp
若是包名是ROOT.WAR,那麼通路路徑是/
若是包名是ROOT-foobar.war,那麼通路路徑是/ 同時建立了一個虛拟主機foobar
本文轉自 guowang327 51CTO部落格,原文連結:http://blog.51cto.com/guowang327/1770883,如需轉載請自行聯系原作者