Changes between Version 4 and Version 5 of waue/2009/0813


Ignore:
Timestamp:
Aug 13, 2009, 5:31:38 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0813

    v4 v5  
    1515}}}
    1616
    17  = ServletHandler =
     17 = Jetty code 最精簡版 =
     18 
     19''' 完整資訊於 [wiki:jetty_demo jetty_demo ] 的 simple_start 資料夾 '''
     20
     21 * jetty.sh
     22
     23{{{
     24#!sh
     25#!/bin/bash
     26export JAVA_HOME=/usr/lib/jvm/java-6-sun
     27export JETTY_HOME=/opt/jetty_demo
     28export THISPATH=/opt/jetty_demo/simple_start
     29export CLASSPATH=$CLASSPATH:$THISPATH:\
     30/opt/jetty_demo/lib/javax.servlet.jar:\
     31/opt/jetty_demo/lib/org.mortbay.jetty.jar:\
     32/opt/jetty_demo/lib/org.mortbay.jmx.jar:\
     33/opt/jetty_demo/ext/ant.jar:\
     34/opt/jetty_demo/ext/jasper-compiler.jar:\
     35/opt/jetty_demo/ext/mx4j-remote.jar:\
     36/opt/jetty_demo/ext/xml-apis.jar:\
     37/opt/jetty_demo/ext/commons-el.jar:\
     38/opt/jetty_demo/ext/jasper-runtime.jar:\
     39/opt/jetty_demo/ext/mx4j-tools.jar:\
     40/opt/jetty_demo/ext/xmlParserAPIs.jar:\
     41/opt/jetty_demo/ext/commons-logging.jar:\
     42/opt/jetty_demo/ext/mx4j.jar:\
     43/opt/jetty_demo/ext/xercesImpl.jar
     44
     45cd $THISPATH
     46
     47# compiler
     48javac -cp $CLASSPATH SimpleJetty.java
     49
     50# run
     51java -cp $CLASSPATH -Djetty.home=$JETTY_HOME SimpleJetty my.xml
     52}}}
     53 
     54 * SimpleJetty.java
     55
     56{{{
     57#java
     58import org.mortbay.http.SocketListener;
     59import org.mortbay.jetty.Server;
     60
     61public class SimpleJetty {
     62
     63        static final String web_root = "/opt/jetty_demo/webapps/root/";
     64        static final int port_num = 8180;
     65
     66        public static void main(String[] args) {
     67                Server server = new Server();
     68                SocketListener listener = new SocketListener();
     69                listener.setPort(port_num);
     70                server.addListener(listener);
     71                try {
     72                        server.addWebApplication("/", web_root);
     73                        server.start();
     74
     75                } catch (Exception e1) {
     76                        e1.printStackTrace();
     77                }
     78
     79        }
     80
     81}
     82
     83}}}
     84
     85 * my.xml
     86
     87{{{
     88<Configure class="org.mortbay.jetty.Server">
     89  <Call name="addListener">
     90    <Arg>
     91      <New class="org.mortbay.http.SocketListener">
     92          <Set name="Port">
     93            <SystemProperty name="jetty.port" default="8180"/>
     94          </Set>
     95      </New>
     96    </Arg>
     97  </Call>
     98
     99  <Call name="addWebApplication">
     100    <Arg>/opt/jetty_demo/webapps/root
     101    </Arg>
     102  </Call>
     103 </Configure>
     104}}}
     105
     106 = 官方程式教學 =
    18107
    19108Using the ServletHandler