Jetty installation, configuration, and use

Jetty is an open source servlet container, which provides a runtime environment for Java-based web content, such as JSP and servlet. Jetty is written in Java language, and its API is released in the form of a set of JAR packages. Developers can instantiate the Jetty container into an object, which can quickly provide network and web connections for stand-alone Java applications. (Jetty is an open source software that can be used as a container for HTTP services, javax.servlet.)

Steps to configure jetty server:

Create server

Configure connector

Configure handler< /p>

Configure servlet

Start server

1. Install maven

Maven is a software based on the Project Object Model (POM), which can manage project construction, reports and documents through a short description of information Project management tool.

  If you have entered the same Ant targets ten times to compile you Code, jar or war, generate javadocs, you must ask yourself if there is a way to do the same job with less repetition. Maven provides such an option to shift your attention from the job level to the project management level. The Maven project already knows how to build and bundle code, run tests, generate documentation and host the project web page.

(1) Download and press jdk and place it under the /usr/local directory:

[root@master ~]#chmod 755 jdk-6u5-Linux-x64.bin

[root@master ~]# ./jdk-6u5-linux-x64.bin

[root@master ~]#mv jdk1.6.0_05 /usr/ local

< span style="color:rgb(255,153,102); background-color:rgb(51,255,51)">Establish a jdk soft connection under /usr/local/ to facilitate future version upgrades:

[root@master ~]# ln -s /usr/local/jdk1.6.0_05/ /usr/local/jdk

(2) Install apache-maven and set environment variables

[root@master zy]# tar -zxvf apache-maven-2.2.1-bin.tar.gz

[root@master zy]# mv apache-maven-2.2.1 /usr/local/maven

[root@master zy]#vim /etc/profile

Add the following:

JAVA_HOME=/usr/local/jdk1.6.0_05

JAVA_BIN=/usr/local/jdk1.6.0_05/bin

PATH=$PATH:$JAVA_BIN:/usr/local/maven/bin

CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

JETTY_HOME=/usr/local/jetty

export JAVA_HOME JAVA_BIN PATH CLASSPATH JETTY_HOME

[root@master zy]# source /etc/profile

[root@master zy]# mvn –version

Apache Maven 2.2.1 (r801777; 200 9-08-07 03:16:01+0800)

Java version: 1.6.0_05

Java home: /usr/local/jdk1.6.0_05/jre

Default locale: en_US, platform encoding: UTF-8

OS name: “linux” version: “2.6.18-238.el5” arch: “amd64” Family: “unix”

2. Install and start jetty

[root@master zy]# unzip jetty-distribution-7.3.0.v20110203.zip

[root@master zy]# mv jetty-distribution-7.3.0.v20110203 /usr/local/jetty/

[root@master zy]# cd /usr/local/jetty/

< p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"> [root@master jetty]# java -jar start.jar [Or go to the bin directory and execute ./jetty.sh start]

[root@master bin]# ./jetty.sh start

Starting Jetty: STARTED Jetty Mon Jul 11 ​​11:54:03 CST 2011

[root@master bin]# 2011-07-11 11:54 :04.014:INFO::Redirecting stderr/stdout to /usr/local/jetty/logs/2011_07_11.stderrout.log

Type in the browserhttp://192.168.55.229:8080/remote.html(The reason for adding remote.html here is to avoid tomcatconflict, in fact, http://192.168.55.229:8080 can also be accessed, but the premise is that tomcat must be banned. Or change the port to 8081 in jetty.xml, then we can directly visit http://192.168.55.229:8081)

The jetty directory structure is as follows:
* contexts hot deployment directory
* etc jetty configuration file directory
* examples jetty example
* extras jetty optional extension
* lib contains the jar files required by jetty
* LICENSES is LICENSES
* modules submodule
* patches Patches
* pom.xml is jetty’s maven2 build file
* project-website jetty7 website
* README.txt readme.txt
* start.jar is jetty7主程序
* VERSION.txt
* webapps应用路径,发布的引用基本都放这里

3. Simple deployment of an application

[root@master ~]# cd /usr/local/jetty/webapps/

[root@master webapps]# ls

test.war

[ root@master webapps]# mkdir test1

[root@ master webapps]# cd test1

[root@master test1 ]# vi hello.jsp

< p style="color:rgb(51,51,51); font-f amily:Arial; font-size:14px; line-height:26px">

simple test

< %--echo hello world--%>

< %@page language="java"%>

< %="Hello World"%>

[root@master test1]# cd /usr/local/jetty/

[root@localhost jetty]#java -jar start.jar

2011-07-11 13:34:16.175:INFO::Deployable added: /usr/local/jetty/webapps/test1

2011-07-1113:34:16.411:INFO::started.ejwWebAppContext {/test1,file:/usr/local/jetty/webapps/test1/},/usr/local/jetty/webapps/test1

[Or go to the bin directory and execute the command. /jetty.sh start]

[root@master bin]# ./jetty.sh start

Starting Jetty: STARTED Jetty Mon Jul 11 ​​13:38:55 CST 2011

[root@master bin]# 2011-07-11 13:38:56.122:INFO: :Redirecting stderr/stdout to /usr/local/jetty/logs/2011_07_11.stderrout.log

Type in the browser:http://192.168.55.229:8080/test1/hello.jsp

Do you think tomcat is very convenient for children’s shoes that used tomcat before? But there is a more convenient web server called jetty, and its size is small, only a few hundred KB, so it is very convenient to use in the project.
Let’s introduce some of the things necessary for jetty< span style="line-height:25px">: Please pay attention to his package structure

These packages are required. You can go to the next version of jetty-7.2 on the Internet that is similar to tomecat.

In fact, there are many ways to use jetty. Let’s analyze them one by one.

Method 1:

Have you seen jetty.xml and webdefault.xml?

The official explanation of webdefault.xml isThe default descriptor is a web.xml format file that is applied to the context before the standard WEB- You can understand INF/web.xml as the configuration file of a container required by jetty that is loaded before web.xml is loaded.

You can go to the jetty you downloaded and take it out, for example Your path D:\jetty-hightide-7.2.1.v20101111\etc Go here and drag it out and put it in your project. Basically do not change the content.

Then let’s look at jetty.xml which is responsible for telling the jetty container to What is your project running.

Let’s take a look at its content first:

Xml code Collection code

  1. xmlversion=“1.0”?>
  2. < span style="color:black">>
  3. <Configure id=“Server”class=“org .mortbay.jetty.Server”>
  4. <Set name= “ThreadPool”>< /span>
  5. <New< span class="attribute" style="color:red">class=“org.mortbay.thread.QueuedThreadPool” >
  6. <Set name=“minThreads”>10Set>
  7. <Set name=“maxThreads”>200Set >
  8. <Setname=“lowThreads”>20Set< span class="tag" style="color:rgb(0,102,153); font-weight:bold">>
  9. <Set name=“SpawnOrShrinkAt”>2Set>
  10. New> span>
  11. Set>
  12. <Callname=“addConnector”< /span>>
  13. <Arg> li>
  14. <Newclass=“org.mortbay.jetty.nio.SelectChannelConnector”>
  15. < span style="color:black">
  16. < Set name=“host” > <SystemPropertyname=“jetty.host” default< /span>=“localhost”/>Set> span>
  17. <Setname=” port”><SystemPropertyname=“jetty.port” default=“9090”/> Set>
  18. <Setname=“maxIdleTime”>30000Set>
  19.             < Set name=“Acceptors” >2Set>    
  20.             <Set name=“statsOn”>falseSet>    
  21.             <Set name=“confidentialPort”>8443Set>    
  22.         <Set name=“lowResourcesConnections”>5000Set>    
  23.         <Set name=“lowResourcesMaxIdleTime”>5000Set>    
  24.           New>    
  25.       Arg>    
  26.     Call>    
  27.     
  28.     <Set name=“handler”>    
  29.       <New id=“Handlers” class=“org.mortbay.jetty.handler.HandlerCollection”>    
  30.         <Set name=“handlers”>    
  31.          <Array type=“org.mortbay.jetty.Handler”>    
  32.            <Item>    
  33.              <New id=“RequestLog” class=“org.mortbay.jetty.handler.RequestLogHandler”/>    
  34.            Item>    
  35.        <Item>    
  36.            <New class=“org.mortbay.jetty.webapp.WebAppContext”>      
  37.               <Set name=“contextPath”>/jettytestSet>      
  38.                           <Set name=“war”>./WebRootSet>      
  39.                  New>      
  40.           Item>    
  41.          Array>    
  42.         Set>    
  43.       New>    
  44.     Set>    
  45.     <Ref id=“RequestLog”>    
  46.       <Set name=“requestLog”>    
  47.         <New id=“RequestLogImpl” class=“org.mortbay.jetty.NCSARequestLog”>    
  48.           <Set name=“filename”><SystemProperty name=“jetty.logs”   default=“./WebRoot/logs”  
  49.          />/yyyy_mm_dd.request.logSet>    
  50.           <Set name=“filenameDateFormat”>yyyy_MM_ddSet>    
  51.           <Set name=“retainDays”>90Set>    
  52.           <Set name=“append”>trueSet>    
  53.           <Set name=“extended”>trueSet>    
  54.           <Set name=“logCookies”>falseSet>    
  55.           <Set name=“LogTimeZone”>GMTSet>    
  56.         New>    
  57.       Set>    
  58.     Ref>    
  59.     <Set name=“stopAtShutdown”>trueSet>    
  60.     <Set name=“sendServerVersion”>trueSet>    
  61.     <Set name=“sendDateHeader”>trueSet>    
  62.     <Set na me=“gracefulShutdown”>1000Set>    
  63. Configure>    
  64.   
  65.    

 

字面就很好理解吧?看完了上面的你啥类都可以先不写,可以进入debug配置里面 如下图

 

右击new 一个如下图来配置

 

 

 

到这里方法1就基本完成了,保存配置 run debug! http://localhost:9090/jettytest 直接去访问吧。

 

方法2和方法3 都是用java代码来call jetty。

方法2先来:

Java代码   收藏代码

  1. public static void startJettyMethodO() {  
  2.         String jetty_home = “jettytest”;//这个就是你的项目发布时候的名字  
  3.          try {  
  4.                 Server server = new Server();  
  5.                 Connector connector = new SelectChannelConnector();  
  6.                 connector.setPort(9999);  
  7.                 server.setConnectors(new Connector[] { connector });  
  8.                 WebAppContext webapp = new WebAppContext();  
  9.                 webapp.setContextPath(“/”+jetty_home);//上下文路径 比如说/jettytest  
  10.                 webapp.setResourceBase(“./WebRoot”);//你的资源文件所在的路径 一般都在这下面   
  11.                 webapp.setDefaultsDescriptor(“./WebRoot/etc/webdefault.xml”);  
  12.                 server.setHandler(webapp);  
  13.                 server.start();  
  14.                 server.join();  
  15.             } catch (Exception e) {  
  16.                 e. printStackTrace();  
  17.             }  
  18.     }  

 

  方法3:

 

Java代码   收藏代码

  1. FileNotFoundException, Exception {  
  2.     Server server = new Server();    
  3.         XmlConfiguration configuration = new XmlConfiguration(    
  4.         new FileInputStream(    
  5.             “D:\\teamwork\\jettytest\\WebRoot\\etc\\jetty.xml”)); //指定自定义的jetty.xml路径    
  6.         configuration.configure(server);    
  7.         server.start();  

 

附:官方apihttp://jetty.codehaus.org/jetty/jetty-6/apidocs/index.html

其他我也没啥好说的了。如果还有其他方法的话我会更新的。多谢支持~!

spiritfrog 写道
总结: 
本文作为jetty的初体验体会,着重于怎样移植webapp到jetty,以及如何快速在jetty上部署webapp,也尝试了嵌入方式启动webapp,这些工作在找到方法后很轻松(实际上我可找了很久)。主要是完成你的webapp对jetty的配置,然后start! 
本文并没有重点讨论jetty.xml的配置,这部分内容可以根据官方文档和看jetty自带的examples来学习,以后有时间看了再说。 

注意: 
jetty6是基于servlet2.5和jsp2.1设计的, 
几个核心包是jetty-6.1.11.jar、jetty-util-6.1.11.jar、servlet-api-2.5-6.1.11.jar; 
如果以嵌入式启动,需要引用jsp2.1包,我一开始引用的是jsp2.0包,结果造成了一些方法调用对不上参数的问题,明显是class版本有差别,换用jsp2.1就可以了。 
另外对于嵌入式,/lib/naming和/lib/plus下的包最好也全部引入。 
有时候jetty配置文件中会有如下引用jetty.home等变量 
/etc/realm.properties 
需要在启动程序配置中加上vm参数,如果是jetty.home,则加上 
-Djetty.home=D:/devworkspace/jetty-6.1.11

 

 

  • jettytest.rar (5.6 MB)
  • 下载次数: 786

之前都用tomcat的童鞋是不是觉得tomcat很方便啊?但是还有个更方便的web服务器叫jetty,而且它的体积很小,只有几百KB,所以在项目中使用是很方便的。  
  下面来介绍下jetty所必需的一些东西:请注意看他的包结构

 

 

这些包都是必需的。你可以去网上下个jetty-7.2版本的类似于tomecat的东西。

其实运用jetty的方法比较多。我们一一来分析。

方法1:

 看到jetty.xml和webdefault.xml这2玩意了吗?

 webdefault.xml官方的解释是 The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml 你可以理解为在web.xml加载之前先加载的jetty所需的一个容器的配置文件。

你可以去你下载的jetty里面拿出来 比如说你的路径D:\jetty-hightide-7.2.1.v20101111\etc 去这里拽个出来放在你项目里面。内容基本上不要改。

然后我们来看下jetty.xml 这是一个负责告诉jetty容器要运行的你的工程是什么。

咱们可以先看下它的内容:

Xml代码   收藏代码

  1. xml version=“1.0”?>    
  2. >    
  3. <Configure id=“Server” class=“org.mortbay.jetty.Server”>    
  4.     <Set name=“ThreadPool”>    
  5.       <New class=“org.mortbay.thread.QueuedThreadPool”>    
  6.         <Set name=“minThreads”>10Set>    
  7.         <Set name=“maxThreads”>200Set>    
  8.         <Set name=“lowThreads”>20Set>    
  9.         <Set name=“SpawnOrShrinkAt”>2Set>    
  10.       New>    
  11.     Set>    
  12.     <Call name=“addConnector”>    
  13.       <Arg>    
  14.           <New class=“org.mortbay.jetty.nio.SelectChannelConnector”>    
  15.                
  16.             <Set name=“host”><SystemProperty name=“jetty.host” default=“localhost”/>Set>    
  17.               
  18.             <Set name=“port”><SystemProperty name=“jetty.port” default=“9090”/>Set>    
  19.             <Set name=“maxIdleTim e”>30000Set>    
  20.             <Set name=“Acceptors”>2 Set>    
  21.             <Set name=“statsOn”>falseSet>    
  22.             <Set name=“confidentialPort”>8443Set>    
  23.         <Set name=“lowResourcesConnections”>5000Set>    
  24.         < span class="tag" style="color:rgb(0,102,153); font-weight:bold"><Set name=“lowResourcesMaxIdleTime”>5000Set>    
  25.           New>    
  26.       Arg>    
  27.     Call>    
  28.     
  29.     <Set name=“handler”>    
  30.       <New id=“Handlers” class=“org.mortbay.jetty.handler.HandlerCollection”>    
  31.         <Set name=“handlers”>    
  32.          <Array type=“org.mortbay.jetty.Handler”>    
  33.            <Item>    
  34.              <New id=“RequestLog”  class=“org.mortbay.jetty.handler.RequestLogHandler”/>    
  35.            Item>    
  36.        <Item>    
  37.            <New class=“org.mortbay.jetty.webapp.WebAppContext”>      
  38.               <Set name=“contextPath”>/jettytestSet>      
  39.                           <Set name=“war”>./WebRootSet>      
  40.                  New>      
  41.           Item>    
  42.          Array>    
  43.         Set>    
  44.       New>    
  45.     Set>    
  46.     <Ref id=“RequestLog”>    
  47.       <Set name=“requestLog”>    
  48.         <New id=“RequestLogImpl” class=“org.mortbay.jetty.NCSARequestLog”>    
  49.           <Set name=“filename”><SystemProperty name=“jetty.logs”   default=“./WebRoot/logs”  
  50.          />/yyyy_mm_dd.request.logSet>    
  51.           <Set name=“filenameDateFormat”>yyyy_MM_ddSet>    
  52.           <Set name=“retainDays”>90Set>    
  53.           <Set name=“append”>trueSet>    
  54.           <Set name=“extended”>trueSet>    
  55.           <Set name=“logCookies”>falseSet>    
  56.           <Set name=“LogTimeZone”>GMTSet>    
  57.         New>    
  58.       Set>    
  59.     Ref>    
  60.     <Set name=“stopAtShutdown”>trueSet>    
  61.     <Set name=“sendServerVersion”>trueSet>    
  62.     <Set name=“sendDateHeader”>trueSet>    
  63.     <Set name=“gracefulShut down”>1000Set>    
  64. Configure>    
  65.   
  66.    

 

字面就很好理解吧?看完了上面的你啥类都可以先不写,可以进入debug配置里面 如下图

 

右击new 一个如下图来配置

 

 

 

到这里方法1就基本完成了,保存配置 run debug! http://localhost:9090/jettytest 直接去访问吧。

 

方法2和方法3 都是用java代码来call jetty。

方法2先来:

Java代码   收藏代码

  1. public static void startJettyMethodO() {  
  2.         String jetty_home = “jettytest”;//这个就是你的项目发布时候的名字  
  3.          try {  
  4.                 Server server = new Server();  
  5.                 Connector connector = new SelectChannelConnector();  
  6.                 connector.setPort(9999);  
  7.                 server.setConnectors(new Connector[] { connector });  
  8.                 WebAppContext w ebapp = new WebAppContext();  
  9.                 webapp.setContextPath(“/”+jetty_home);//上下文路径 比如说/jettytest  
  10.                 webapp.setResourceBase(“./WebRoot”);//你的资源文件所在的路径 一般都在这下面   
  11.                 webapp.setDefaultsDescriptor(“./WebRoot/etc/webdefault.xml”);  
  12.                 server.setHandler(webapp);  
  13.                 server.start();  
  14.                 server.join();  
  15.             } catch (Exception e) {  
  16.                 e.printStackTrace();  
  17.             }  
  18.     }  

 

  方法3:

 

Java代码   收藏代码

  1. FileNotFoundException, Exception {  
  2.     Server server = new Server();    
  3.         XmlConfiguration configuration = new XmlConfiguration(    
  4.         new FileInputStream(    
  5.             “D:\\teamwork\\jettytest\\WebRoot\\etc\\jetty.xml”)); //指定自定义的jetty.xml路径    
  6.         configuration.configure(server);    
  7.         server.start();  

 

附:官方apihttp://jetty.codehaus.org/jetty/jetty-6/apidocs/index.html

其他我也没啥好说的了。如果还有其他方法的话我会更新的。多谢支持~!

spiritfrog 写道
总结: 
本文作为jetty的初体验体会,着重于怎样移植webapp到jetty,以及如何快速在jetty上部署webapp,也尝试了嵌入方式启动webapp,这些工作在找到方法后很轻松(实际上我可找了很久)。主要是完成你的webapp对jetty的配置,然后start! 
本文并没有重点讨论jetty.xml的配置,这部分内容可以根据官方文档和看jetty自带的examples来学习,以后有时间看了再说。 

注意: 
jetty6是基于servlet2.5和jsp2.1设计的, 
几个核心包是jetty-6.1.11.jar、jetty-util-6.1.11.jar、servlet-api-2.5-6.1.11.jar; 
如果以嵌入式启动,需要引用jsp2.1包,我一开始引用的是jsp2.0包,结果造成了一些方法调用对不上参数的问题,明显是class版本有差别,换用jsp2.1就可以了。 
另外对于嵌入式,/lib/naming和/lib/plus下的包最好也全部引入。 
有时候jetty配置文件中会有如下引用jetty.home等变量 
/etc/realm.properties 
需要在启动程序配置中加上vm参数,如果是jetty.home,则加上 
-Djetty.home=D:/devworkspace/jetty-6.1.11

 

 

Xml代码   收藏代码

  1. xml version=“1.0”?>    
  2. >    
  3. <Configure id=“Server” class=“org.mortbay.jetty.Server”>    
  4.     <Set name=“ThreadPool”>    
  5.       <New class=“org.mortbay.thread.QueuedThreadPool”>    
  6.         <Set name=“minThreads”>10Set>    
  7.         <Set name=“maxThreads”>200Set>    
  8.         <Set name=“lowThreads”>20Set>    
  9.         <Set name=“SpawnOrShrinkAt”>2Set>    
  10.       New>    
  11.     Set>    
  12.     <Call name=“addConnector”>    
  13.       <Arg>    
  14.           <New class=“org.mortbay.jetty.nio.SelectChannelConnector”>    
  15.                
  16.             <Set name=“host”><SystemProperty name=“jetty.host” default=“localhost”/>Set>    
  17.               
  18.             <Set name=“port”><SystemProperty name=“jetty.port”  default=“9090”/>Set>    
  19.             <Set name=“maxIdleTime”>3 0000Set>    
  20.             <Set name=“Acceptors”>2Set>    
  21.             <Set name=“statsOn”>falseSet>    
  22.             <Set name=“confidentialPort”>8443Set>    
  23.         <Set name=“lowResourcesConnections”>5000Set>    
  24.         <Set name=“lowResourcesMaxIdleTime”>5000Set>    
  25.           New>    
  26.       Arg>    
  27.     Call>    
  28.     
  29.     <Set name=“handler”>    
  30.       <New id=“Handlers” class=“org.mortbay.jetty.handler.HandlerCollection”>    
  31.         <Set name=“handlers”>    
  32.          <Array type=“org.mortbay.jetty.Handler”>    
  33.            <Item>    
  34.              <New id=“RequestLog” class=“org.mortbay.jetty.handler.RequestLogHandler”/>    
  35.            Item>    
  36.        <Item>    
  37.            <New class=“org.mortbay.jetty.webapp.WebAppContext”>      
  38.               <Set name=“contextPath”>/jettytestSet>      
  39.                           <Set name=“war”>./WebRootSet>      
  40.                  New>      
  41.           Item>    
  42.          Array>    
  43.         Set>    
  44.       New>    
  45.     Set>    
  46.     <Ref id=“RequestLog”>    
  47.       <Set name=“requestLog”>    
  48.         <New id=“RequestLogImpl” class=“org.mortbay.jetty.NCSARequestLog”>    
  49.           <Set name=“filename”><SystemProperty name=“jetty.logs”   default=“./WebRoot/logs”  
  50.          />/yyyy_mm_dd.request.logSet>    
  51.           <Set name=“filenameDateFormat”>yyyy_MM_ddS et>    
  52.           <Set name=“retainDays”>90Set>    
  53.           <Set name=“append”>trueSet>    
  54.           <Set name=“extended”>trueSet>    
  55.           <Set name=“logCookies”>falseSet>    
  56.           <Set name=“Lo gTimeZone”>GMTSet>    
  57.         New>    
  58.       Set>    
  59.     Ref>    
  60.     <Set name=“stopAtShutdown”>trueSet>    
  61.     <Set name=“sendServerVersion”>trueSet>    
  62.     <Set name=“sendDateHeader”>trueSet>    
  63.     <Set name=“gracefulShutdown”>1000Set>    
  64. Configure>    
  65.   
  66.    

Xml代码   收藏代码

Xml代码   收藏代码

Java代码   收藏代码

  1. public static void startJettyMethodO() {  
  2.         String jetty_home = “jettytest”;//这个就是你的项目发布时候的名字  
  3.          try {  
  4.                 Server server = new Server();  
  5.                 Connector connector = new SelectChannelConnector();  
  6.                 connector.setPort(9999);  
  7.                 server.setConnectors(new Connector[] { connector });  
  8.                 WebAppContext webapp = new WebAppContext();  
  9.                 webapp.setContextPath(“/”+jetty_home);//上下文路径 比如说/jettytest  
  10.                 webapp.setResourceBase(“./WebRoot”);//你的资源文件所在的路径 一般都在这下面   
  11.                 webapp.setDefaultsDescriptor(“./WebRoot/etc/webdefault.xml”);  
  12.                 server.setHandler(webapp);  
  13. < li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">                 server.start();  

  14.                 server.join();  
  15.             } catch (Exception e) {  
  16.                 e.printStackTrace();  
  17.             }  
  18.     }  

Java代码   收藏代码

Java代码   收藏代码

Java代码   收藏代码

  1. FileNotFoundException, Exception {  
  2.     Server server = new Server();    
  3.         XmlConfiguration configuration = new XmlConfiguration(    
  4.         new FileInputStream(    
  5.             “D:\\teamwork\\jettytest\\WebRoot\\etc\\jetty.xml”)); //指定自定义的jetty.xml路径    
  6.         configuration.configure(server);    
  7.         server.start();  

Java代码   收藏代码

Java代码   收藏代码

spiritfrog 写道

总结: 
本文作为jetty的初体验体会,着重于怎样移植webapp到jetty,以及如何快速在jetty上部署webapp,也尝试了嵌入方式启动webapp,这些工作在找到方法后很轻松(实际上我可找了很久)。主要是完成你的webapp对jetty的配置,然后start! 
本文并没有重点讨论jetty.xml的配置,这部分内容可以根据官方文档和看jetty自带的examples来学习,以后有时间看了再说。 

注意: 
jetty6是基于servlet2.5和jsp2.1设计的, 
几个核心包是jetty-6.1.11.jar、jetty-util-6.1.11.jar、servlet-api-2.5-6.1.11.jar; 
如果以嵌入式启动,需要引用jsp2.1包,我一开始引用的是jsp2.0包,结果造成了一些方法调用对不上参数的问题,明显是class版本有差别,换用jsp2.1就可以了。 
另外对于嵌入式,/lib/naming和/lib/plus下的包最好也全部引入。 
有时候jetty配置文件中会有如下引用jetty.home等变量 
/etc/realm.properties 
需要在启动程序配置中加上vm参数,如果是jetty.home,则加上 
-Djetty.home=D:/devworkspace/jetty-6.1.11

  • jettytest.rar (5.6 MB)
  • 下载次数: 786

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4568 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.