2011-11-21
儿個月前試用了一陣子Jetty,當時對Jetty印象蠻好的。如果需要的是一個非常輕量或是可模組化設定的APServer,可以考慮這東東。不過...我自己用一陣子後還是換回Tomcat就是了...XD...這不是說Jetty不好,而是因為剛好Tomcat上有一些現成Webbase的APServer monitor工具,但是Jetty沒有。我又蠻需要這些工具,所以就還是換回Tomcat了。有時...好維護比高效來的重要呀...<(T_T)>
癈言結束,Jetty筆記(以7.4.5版本為基準)正文開始~~~
==================================================================
快速上手簡介
請參考JavaWorld@TW的
這篇文章
==================================================================
使用的好處,我個人覺的有這儿點
1.速度快
2.功能模組化,可以只啟用想要用的功能(e.g. 讓它只支援Servlet,不支援JSP)
3.還有很多,請上官網查詢
==================================================================
Jetty比較重要的子目錄與相關說明如下
Z:\JETTY-7.4.5==================================================================
├─bin --> 存放Jetty的啟動批次檔(只有linux版的bash script)。此目錄等同於tomcat的/bin。
├─contexts --> 存放hot deploy相關設定檔(e.g. 如果有一個app叫test.war,可在這裡寫個test.xml設定檔,檔內可設定ContextPath相關設定。此目錄等同於tomcat的/conf。
├─contexts-available
├─etc --> 存放Jetty各功能模組的設定檔(e.g. jetty.xml、jetty-ssl.xml),其中最重要的一個是jetty.xml,Jetty在啟動時一定要載入此設定檔。
├─lib
│ ├─annotations
│ ├─ext
│ ├─jndi
│ ├─jsp
│ ├─jta
│ └─policy
├─logs
├─overlays
│ ├─instances
│ ├─nodes
│ ├─templates
│ └─webapps
├─resources
└─webapps --> 存放各個webapp(war檔格式)的地方。此目錄等同於tomcat的/webapps。
啟動指令:java -jar start.jar也可以用指定StopPort的方式來啟動與關閉Jetty,範例如下
關閉指令:直接按[Ctrl + C]
啟動指令:java -DSTOP.PORT=8888 -DSTOP.KEY=jetty-password -jar start.jar
啟動指令:java -DSTOP.PORT=8888 -DSTOP.KEY=jetty-password -jar start.jar --stop
註:"STOP.PORT"用來指定要停止Jetty時所用的port,"STOP.KEY"用來指定要停止Jetty時,所用的密碼
"java -jar start.jar --list-options"指令:列出Jetty的"OPTIONS"參數可以設定的設定值清單==================================================================
"java -jar start.jar --dry-run"指令:Print the command line that the start.jar generates,then exit. This may be used to generate command lines(不啟動Jetty,只列出啟動Jetty時,jvm實際上被呼叫的Consle指令)
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<!-- 指定http connection port -->
<Set name="port"><Property name="jetty.port" default="8080"/></Set>
<!-- 指定connection time out的等待時間,單位為millisec -->
<Set name="maxIdleTime">43200000</Set>
<!-- 指定同一時間可以處理多少個request,同一時間要處理多個client的需求時,此值要加大。此值的設定跟CPU有關,CPU不夠力時,這個值不能設太大 -->
<Set name="Acceptors">2</Set>
<!-- 指定https connection port -->
<Set name="confidentialPort">8443</Set>
</New>
</Arg>
</Call>
acceptRanges If true, range requests and responses are
supported
dirAllowed If true, directory listings are returned if no
welcome file is found. Else 403 Forbidden.
welcomeServlets If true, attempt to dispatch to welcome files
that are servlets, but only after no matching static
resources could be found. If false, then a welcome
file must exist on disk. If "exact", then exact
servlet matches are supported without an existing file.
Default is true.
This must be false if you want directory listings,
but have index.jsp in your welcome file list.
redirectWelcome If true, welcome files are redirected rather than
forwarded to.
gzip If set to true, then static content will be served as
gzip content encoded if a matching resource is
found ending with ".gz"
resourceBase Set to replace the context resource base
resourceCache If set, this is a context attribute name, which the servlet
will use to look for a shared ResourceCache instance.
relativeResourceBase
Set with a pathname relative to the base of the
servlet context root. Useful for only serving static content out
of only specific subdirectories.
aliases If True, aliases of resources are allowed (eg. symbolic
links and caps variations). May bypass security constraints.
maxCacheSize The maximum total size of the cache or 0 for no cache.
maxCachedFileSize The maximum size of a file to cache
maxCachedFiles The maximum number of files to cache
useFileMappedBuffer
If set to true, it will use mapped file buffer to serve static content
when using NIO connector. Setting this value to false means that
a direct buffer will be used instead of a mapped file buffer.
By default, this is set to true.
cacheControl If set, all static content will have this value set as the cache-control
header.
user1 password1
user1 readonly
java ^
-Dcom.sun.management.jmxremote ^
-Djava.rmi.server.hostname=127.0.0.1 ^
-Dcom.sun.management.jmxremote.port=1099 ^
-Dcom.sun.management.jmxremote.ssl=false ^
-Dcom.sun.management.jmxremote.authenticate=true ^
-Dcom.sun.management.jmxremote.access.file=jmxremote.access ^
-Dcom.sun.management.jmxremote.password.file=jmxremote.password ^
-jar start.jar
url:127.0.0.1:1099
username:user1
password:password1