安裝 Jetty
jetty 前言
- 本篇 雖然說明了兩種安裝jetty 的方式,但是還是建議去jetty 官網下載 jetty的原始壓縮檔來安裝,因為包含了src才能看原始碼
- 若要jetty上手,還是請使用jetty-demo
jetty 特性
- 易用性
- 通過 XML 或者 API 來對 Jetty 進行配置;
- 默認配置可以滿足大部分的需求;
- 將 Jetty 嵌入到應用程序當中只需要非常少的代碼;
- 可擴展性
- 即使在有大量服務請求的情況下(如Ajax 的 Web 2.0),系統的性能也能保持在一個可以接受的狀態。
- 利用 Continuation 機制來處理大量的用戶請求以及時間比較長的連接。
- 易嵌入性
- Jetty 設計之初就是作為一個優秀的組件來設計的,這也就意味著 Jetty 可以非常容易的嵌入到應用程序當中而不需要程序為了使用 Jetty 做修改。從某種程度上,你也可以把 Jetty 理解為一個嵌入式的Web服務器。
apt-get 之 jetty
安裝jetty
- debian安裝方法
- 在ubuntu用apt-get 安裝得到 jetty 5.1.14版 (2007/8/9) 與 hadoop 0.18.3 的lib 內放的jar檔版本相同
$ sudo apt-get install jetty jetty-extra libecj-java
- ubuntu 安裝後的目錄與debian有些不同
/usr/share/jetty/ | jetty home | |
cgi-bin/ | 0 | |
ext/ | 0 | |
lib/ | jar檔 | |
webapps/ | root下有預設網站 | |
/usr/share/doc/jetty/ | 文件目錄 | |
/var/log/jetty/ | log | |
/usr/share/java/ | jetty-5.0.0.jar | 主程式 |
/etc/jetty/ | 設定檔 | |
/etc/default/ | jetty | 0 |
/etc/init.d/ | jetty | 驅動檔 |
啟動 jetty
- 設定 jetty -> /etc/jetty/jetty.xml
<Set name="Port"><SystemProperty name="jetty.port" default="8280"/></Set>
- 啟動
$sudo /etc/init.d/jetty start
- 瀏覽 http://localhost:8280/
- ps : 不知設定檔如何找出port :
- 先用 ps aux | jetty 找出jetty的pid
- 在用pid 來探索 netstat -anlp | grep $pid ,可查出port號如
tcp6 0 0 :::8280 :::* LISTEN 30597/java
- 在/etc/jetty/start.config 加入
$(tomcat.lib.home)/jasper-compiler-jdt.jar ! available org.eclipse.jdt.core.JDTCompilerAdapter
- 預設port在8280
- ps2: jetty的預設網頁裡的tutorial 還不錯
問題解決
- 用 apt-get install jetty 所安裝的jetty無法開啟jsp的網頁
- 將會出現錯誤訊息
HTTP ERROR: 500 No Java compiler available RequestURI=/sample/hello.jsp
- 將會出現錯誤訊息
- 解決方法:
sudo apt-get install libecj-java
並在/etc/jetty/start.config 加入
$(tomcat.lib.home)/jasper-compiler-jdt.jar ! available org.eclipse.jdt.core.JDTCompilerAdapter
補充分析
- apt-get 安裝的 jetty ,在無安裝libecj-java以及加入jasper-compiler-jdt.jar 前,無法使用jsp,但 tarball的jetty 在同樣的前提下卻可以,而tarball 的lib , ext 的目錄下也沒有jasper-compiler-jdt.jar ,因此分析一下 start.config的不同
$ diff -Naur /home/waue/Desktop/start.config /etc/jetty/start.config
--- jetty-src 包在start.jar內的 start.config (左) +++ /etc/jetty/的 start.config (右)
-
start.config
old new 22 22 # CONDITION is one of: 23 23 # always 24 24 # never 25 # available classname # true if class on classpath 26 # property name # true of set 27 # java OPERATOR version # java version compared to literal 28 # nargs OPERATOR number # number of command line args compared to literal 25 # available classname 26 # java OPERATOR version 27 # nargs OPERATOR number 29 28 # OPERATOR := one of "<",">","<=",">=","==","!=" 30 29 # 31 30 # CONTITIONS can be combined with AND OR or !, with AND being the assume … … 36 35 37 36 $(jetty.class.path) always 38 37 39 org.mortbay.log.LogFactory.noDiscovery=true ! property org.mortbay.log.LogFactory.noDiscovery 40 javax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder java > 1.4 38 org.apache.commons.logging.LogFactory=org.mortbay.log.Factory AND ! property org.apache.commons.logging.LogFactory ! property org.apache.commons.logging.Log 41 39 42 40 # Try different settings of jetty.home until the jetty.jar is found. 43 jetty.home=. ! exists $(jetty.home)/lib/org.mortbay.jetty.jar 44 jetty.home=.. ! exists $(jetty.home)/lib/org.mortbay.jetty.jar 45 jetty.home=/home/jetty ! exists $(jetty.home)/lib/org.mortbay.jetty.jar 46 jetty.home=/C:/jetty ! exists $(jetty.home)/lib/org.mortbay.jetty.jar 47 jetty.home=. ! exists $(jetty.home)/lib/org.mortbay.jetty.jar 41 jetty.home=/usr/share/jetty 42 43 # Debian jars home 44 java.lib.home=/usr/share/java always 45 tomcat.lib.home=/usr/share/tomcat5.5/common/lib/ always 46 47 # Do not validate xml files by default. 48 # Disabled because servlet-2.3.jar references an XSD which is not longer 49 # hostet by IBM. This should generally make the startup faster. 50 property=org.mortbay.xml.XmlParser.NotValidating=true 48 51 49 52 # The main class to run 50 org.mortbay.jetty.Server.class 51 # override class with old property name 52 $(start.class).class 53 # override class with preferred property name 54 $(main.class).class 53 org.mortbay.jetty.Server.class 55 54 56 55 # The default configuration files 57 $(jetty.home)/etc/admin.xmlnargs == 058 $(jetty.home)/etc/jetty.xmlnargs == 056 #/etc/admin.xml nargs == 0 57 /etc/jetty/jetty.xml nargs == 0 59 58 60 59 # Set the jetty classpath 61 $(jetty.home)/lib/org.mortbay.jetty.jar java >= 1.4 62 $(jetty.home)/lib/javax.servlet.jar always 63 64 # Add JMX jars 65 $(jetty.home)/lib/org.mortbay.jmx.jar java >= 1.4 60 # Always use the >1.2 version because version matching does not work with kaffe 61 $(jetty.home)/lib/org.mortbay.jetty.jar 62 #$(jetty.home)/lib/org.mortbay.jetty.jar java >= 1.4 63 #$(jetty.home)/extra/lib/org.mortbay.jetty-jdk1.2.jar java < 1.4 AND java >= 1.2 64 $(jetty.home)/lib/org.mortbay.jmx.jar 65 $(java.lib.home)/servlet-api-2.4.jar 66 $(java.lib.home)/jsp-api-2.0.jar 66 67 67 # Always use xercesImpl from extif it is present68 $(j etty.home)/ext/xercesImpl.jar ! available org.apache.xerces.jaxp.DocumentBuilderImpl68 # Always use xercesImpl from debian if it is present 69 $(java.lib.home)/xercesImpl.jar ! available org.apache.xerces.jaxp.DocumentBuilderImpl.class 69 70 70 71 # Add the XML support jars if needed. 71 $(j etty.home)/ext/xmlParserAPIs-2.5.jar! available org.w3c.dom.DOMError72 $(j etty.home)/ext/xml-apis.jar! available org.w3c.dom.Document72 $(java.lib.home)/xmlParserAPIs.jar ! available org.w3c.dom.DOMError 73 $(java.lib.home)/xml-apis.jar ! available org.w3c.dom.Document 73 74 74 75 # Set the classpath for the supporting cast 75 $(jetty.home)/ext/ant.jar ! available org.apache.tools.ant.Main 76 $(jetty.home)/ext/jasper-runtime.jar ! available org.apache.jasper.Constants 77 $(jetty.home)/ext/jasper-compiler.jar ! available org.apache.jasper.JspCompilationContext 78 $(jetty.home)/ext/jnet.jar ! available javax.net.SocketFactory 79 $(jetty.home)/ext/jsse.jar ! available javax.net.ssl.SSLServerSocket 80 $(jetty.home)/ext/jcert.jar ! available javax.security.cert.X509Certificate 81 # Add anything in ext we have not yet considered. 82 $(jetty.home)/ext/* 83 84 # Try some standard locations for anything missing. 85 /usr/share/java/ant.jar ! available org.apache.tools.ant.Main 76 $(java.lib.home)/commons-logging.jar ! available org.apache.commons.logging.LogFactory 77 $(java.lib.home)/commons-el.jar ! available org.apache.commons.el.ExpressionEvaluatorImpl 78 $(java.lib.home)/jmxri.jar ! available javax.management.MBeanServer 79 $(tomcat.lib.home)/jasper-compiler-jdt.jar ! available org.eclipse.jdt.core.JDTCompilerAdapter 80 $(tomcat.lib.home)/jasper-runtime.jar ! available org.apache.jasper.Constants 81 $(tomcat.lib.home)/jasper-compiler.jar ! available org.apache.jasper.JspCompilationContext 82 $(java.lib.home)/ant-1.6.jar ! available org.apache.tools.ant.BuildException 86 83 $(java.home)/lib/tools.jar ! available com.sun.tools.javac.Main 87 84 $(java.home)/../lib/tools.jar ! available com.sun.tools.javac.Main 88 85 89 # Add a resources directory if it is there90 $(jetty.home)/ resources/86 # Add anything in ext we have not yet considered. 87 $(jetty.home)/ext/*
src 之 jetty
安裝
- 此處下載 http://dist.codehaus.org/jetty/
- 解壓縮即可
啟動
cd $jetty_home java -jar start.jar etc/jetty.xml
用jetty 的 eclipse plugin
- eclipse plugin
- 新增 Jetty Web Container 環境(Server)(似乎eclipse 3.2版才有效)
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure id="Server" class="org.mortbay.jetty.Server"> <Call name="addConnector"> <Arg> <New class="org.mortbay.jetty.nio.SelectChannelConnector"> <Set name="port">8080</Set> <Set name="maxIdleTime">30000</Set> <Set name="lowResourcesConnections">5000</Set> <Set name="lowResourcesMaxIdleTime">5000</Set> </New> </Arg> </Call> <Set name="handler"> <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.mortbay.jetty.Handler"> <Item> <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/> </Item> <Item> <New class="org.mortbay.jetty.webapp.WebAppContext"> <Set name="contextPath">/</Set> <Set name="resourceBase">F:/Data/WebApp</Set> <Set name="overrideDescriptor">config/JettyWeb.xml</Set> </New> </Item> </Array> </Set> </New> </Set> </Configure>
補充
- hadoop的web server 用jetty 所搭配的 資料夾與 port 對應
$hadoop_home/webapps/task/ 50060 $hadoop_home/webapps/dfs/ 50070 $hadoop_home/webapps/datanode/ 50010 $hadoop_home/webapps/job/ 50030 $hadoop_home/webapps/task/ 50060 $hadoop_home/webapps/dfs/ 50070
更多資料
Last modified 15 years ago
Last modified on Aug 14, 2009, 12:31:47 PM