bdjhx 发表于 2017-2-25 12:46:32

jetty入门配置

  1、下载:下http://dist.codehaus.org/jetty
  解压到如E:\jetty-6.1.14,其中比较重要的目录是:etc、contexts、webapps。个人认为可以类比tomcat的conf、conf\Catalina\localhost、webapps目录。contexts是热部署用的。
  试运行下,可以把一个简单的web项目到到webapps目录下,或是*.war,如:web-demo(或web-demo.war)放到webapps目录下。进入jetty目录运行 java -jar start.jar 启动jetty服务器

E:\jetty-6.1.14>java -jar start.jar
2009-01-13 15:34:38.937::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2009-01-13 15:34:39.265::INFO: jetty-6.1.14
2009-01-13 15:34:39.421::INFO: Deploy E:\jetty-6.1.14\contexts\javadoc.xml -> org.mortbay.jetty.handler.ContextHandler@15cda3f{/javadoc,file:/E:/jetty-6.1.14/javadoc/}
...
2009-01-13 15:35:01.828::INFO: Opened E:\jetty-6.1.14\logs\2009_01_13.request.log
2009-01-13 15:35:01.953::INFO: Started SelectChannelConnector@127.0.0.1:8080

  打开:http://localhost:8080/web-demo ,恩有结果了。
  2、如果不把web-demo放到webapps目录下也可,在contexts目录下建立一个文件告诉jetty就行了。可以在contexts目录下复制test.xml为web-demo.xml,然后修改如下:

<?xml version="1.0"encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<!-- ==================================================================
Configure and deploy the test web application in $(jetty.home)/webapps/test
Note. If this file did not exist or used a context path other that /test
then the default configuration of jetty.xml would discover the test
webapplication with a WebAppDeployer.By specifying a context in this
directory, additional configuration may be specified and hot deployments
detected.
===================================================================== -->
<Configure class="org.mortbay.jetty.webapp.WebAppContext">

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration :                        -->
<!--+ contextPath                                                -->
<!--+ war OR resourceBase                                          -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/web_demo</Set>
<Set name="war">e:/workspace/web-demo/WebContent</Set>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Optional context configuration                                  -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="extractWAR">false</Set>
<Set name="copyWebDir">false</Set>
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
</Configure>
页: [1]
查看完整版本: jetty入门配置