wiki:waue/2009/0811

Version 26 (modified by waue, 15 years ago) (diff)

--

安裝 Jetty

jetty 前言

  • 本篇 雖然說明了兩種安裝jetty 的方式,但是還是建議去jetty 官網下載 jetty的原始壓縮檔來安裝,因為包含了src才能看原始碼
  • 若要jetty上手,還是請使用jetty-demo

jetty 特性

  • 易用性
    1. 通過 XML 或者 API 來對 Jetty 進行配置;
    2. 默認配置可以滿足大部分的需求;
    3. 將 Jetty 嵌入到應用程序當中只需要非常少的代碼;
  • 可擴展性
    1. 即使在有大量服務請求的情況下(如Ajax 的 Web 2.0),系統的性能也能保持在一個可以接受的狀態。
    2. 利用 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
    
  • 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
      
    • 預設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

src 之 jetty

安裝

啟動

cd $jetty_home
java -jar start.jar etc/jetty.xml

用jetty 的 eclipse plugin

http://sites.google.com/site/javacodelibrary/_/rsrc/1240252400400/java-net/jetty/Jetty_Eclipse.png

<?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

更多資料