- 浏览: 49194 次
- 性别:
- 来自: 成都
最新评论
-
yaoyqsz:
connector.setPort(9999); ----& ...
jetty的使用 -
长夜慢慢:
很有帮助,辛苦了!!!
java web.xml listener filter servlet
jetty的使用
之前都用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 version="1.0"?>
- <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
- <Configure id="Server" class="org.mortbay.jetty.Server">
- <Set name="ThreadPool">
- <New class="org.mortbay.thread.QueuedThreadPool">
- <Set name="minThreads">10</Set>
- <Set name="maxThreads">200</Set>
- <Set name="lowThreads">20</Set>
- <Set name="SpawnOrShrinkAt">2</Set>
- </New>
- </Set>
- <Call name="addConnector">
- <Arg>
- <New class="org.mortbay.jetty.nio.SelectChannelConnector">
- <!--你的IP-->
- <Set name="host"><SystemProperty name="jetty.host" default="localhost"/></Set>
- <!--你的端口-->
- <Set name="port"><SystemProperty name="jetty.port" default="9090"/></Set>
- <Set name="maxIdleTime">30000</Set>
- <Set name="Acceptors">2</Set>
- <Set name="statsOn">false</Set>
- <Set name="confidentialPort">8443</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">/jettytest</Set>
- <Set name="war">./WebRoot</Set> <!--你的web应用根目录-->
- </New>
- </Item>
- </Array>
- </Set>
- </New>
- </Set>
- <Ref id="RequestLog">
- <Set name="requestLog">
- <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
- <Set name="filename"><SystemProperty name="jetty.logs" default="./WebRoot/logs"
- />/yyyy_mm_dd.request.log</Set>
- <Set name="filenameDateFormat">yyyy_MM_dd</Set>
- <Set name="retainDays">90</Set>
- <Set name="append">true</Set>
- <Set name="extended">true</Set>
- <Set name="logCookies">false</Set>
- <Set name="LogTimeZone">GMT</Set>
- </New>
- </Set>
- </Ref>
- <Set name="stopAtShutdown">true</Set>
- <Set name="sendServerVersion">true</Set>
- <Set name="sendDateHeader">true</Set>
- <Set name="gracefulShutdown">1000</Set>
- </Configure>
字面就很好理解吧?看完了上面的你啥类都可以先不写,可以进入debug配置里面 如下图
右击new 一个如下图来配置
到这里方法1就基本完成了,保存配置 run debug!http://localhost:9090/jettytest 直接去访问吧。
方法2和方法3 都是用java代码来call jetty。
方法2先来:
- public static void startJettyMethodO() {
- String jetty_home = "jettytest";//这个就是你的项目发布时候的名字
- try {
- Server server = new Server();
- Connector connector = new SelectChannelConnector();
- connector.setPort(9999);
- server.setConnectors(new Connector[] { connector });
- WebAppContext webapp = new WebAppContext();
- webapp.setContextPath("/"+jetty_home);//上下文路径 比如说/jettytest
- webapp.setResourceBase("./WebRoot");//你的资源文件所在的路径 一般都在这下面
- webapp.setDefaultsDescriptor("./WebRoot/etc/webdefault.xml");
- server.setHandler(webapp);
- server.start();
- server.join();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
方法3:
- FileNotFoundException, Exception {
- Server server = new Server();
- XmlConfiguration configuration = new XmlConfiguration(
- new FileInputStream(
- "D:\\teamwork\\jettytest\\WebRoot\\etc\\jetty.xml")); //指定自定义的jetty.xml路径
- configuration.configure(server);
- server.start();
附:官方apihttp://jetty.codehaus.org/jetty/jetty-6/apidocs/index.html
其他我也没啥好说的了。如果还有其他方法的话我会更新的。多谢支持~!
本文作为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等变量
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
需要在启动程序配置中加上vm参数,如果是jetty.home,则加上
-Djetty.home=D:/devworkspace/jetty-6.1.11
- jettytest.rar (5.6 MB)
- 下载次数: 152
发表评论
-
MongoDB安装
2013-01-05 11:02 703MongoDB安装 MongoDB ... -
SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
2012-09-16 23:19 866一 开发环境 1、动态web工程 2、部分依赖 ... -
Java之IO流学习总结 (转载备忘)
2012-08-03 13:12 512转载自:http://88889999.iteye.com/b ... -
SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结 (转载备忘用)
2012-06-18 22:39 949SpringMVC + spring3.1.1 + hiber ... -
jQuery.extend 函数详解
2012-04-14 11:31 839JQuery的extend扩展方法: Jque ... -
eclipse插件——jinto 资源配置文件 properties 编辑插件
2012-03-15 13:47 1829eclipse插件——jinto 资源配置文件 propert ... -
JAVA 注解示例 详解
2012-02-29 13:55 925JAVA 注解示例 详解 注解(Annotation) ... -
Spring注解讲解
2012-02-29 13:19 784Spring注解讲解 1. 使用Spring注解来注入属性 ... -
html中的数据岛:利用DSO和javascript在html中动态加载和浏览xml数据
2012-02-28 16:50 2567html中的数据岛:利用DSO和javascript在ht ... -
JSTL标签备忘
2012-02-27 14:50 726JSTL标签用法 JSP 标准标记库( Sta ... -
EL表达式详解(转载文档)
2012-02-23 16:46 1053EL表达式 1、EL简介1)语法结构 $ ... -
EL表达式 (转载)
2012-02-23 16:42 805EL表达式 2009-03-27 ... -
struts2 2.3.1.1启动异常原因
2012-02-15 13:53 1203Exception starting filter str ... -
java web.xml listener filter servlet
2011-03-24 20:08 1459jsp开发中的 监听器和过滤器,这两个东西要说起来,很大,很繁 ... -
Java Annotation详解
2011-03-03 11:55 4747元数据的作用 如果要对于元数据的作用进行分类,目前还没有 ... -
oracle在SQLPLUS 和PLSQL建 job 的区别
2011-02-14 15:53 3127//建立job variable tes ... -
plsql中job学习
2011-02-14 15:51 943plsql中学习job --学习job -- ... -
log4j配置解读
2011-02-14 09:51 792log4j.properties 使用 一.参数意义说明 ... -
路径问题--web项目中读写properties文件
2010-11-04 10:02 2203properties文件一般放在工程的src根目录下,然后通过 ... -
基础巩固--概念总结(spring security、Quartz、JUnit测试,等)
2010-11-04 09:52 1963面试时可能有用 1、Spring Security 的大体框架 ...
相关推荐
Jetty使用总结
Java Web服务器Jetty使用手册
jetty是什么 jetty配置 jetty使用 jetty嵌入 jetty启动 jetty部署 jetty教程 jetty嵌入式 jetty
jetty axis2.war文件在axis2-1.7.8-bin.zip下; jetty安装目录下的webapp文件夹下面需要用到此war,jetty才能支持axis2
Jetty cometd(Continuation)学习笔记,自己用的,别人那down的网页
Jetty 这个项目成立于 1995 年,现在已经有非常多的成功产品基于 Jetty,比如 Apache Geromino, JBoss, IBM Tivoli, Cisco SESM 等。Jetty 可以用来作为一个传统的 Web 服务器,也可以作为一个动态的内容服务器,...
引入到eclipse可以直接使用Starter类运行。 包含必备jar包:jetty-6.1.26.jar,jetty-util-6.1.26,servlet的相关jar包。 jetty入门级源代码。
jetty
Jetty9 配置使用HTTPS证书,访问你的服务器更安全,更好的配置方法。
jetty-security-9.4.8.v20171121.jar,jetty-io-9.4.8.v20171121.jar,jetty-continuation-9.4.8.v20171121.jar,jetty-client-9.4.8.v20171121.jar,jetty-jmx-9.4.8.v20171121.jar,jetty-plus-9.4.8.v20171121....
嵌入式jetty服务器开发的所有用到的jar包 包括基础jetty使用的和编译使用的ant的jar全都全了 一次性导入再也不用为找jetty依赖jar包而麻烦了
eclipse jetty插件,从...下载run-jetty-run.zip文件,解压后再编写个links文件丢到eclipse的dropins目录下即可,省去了使用eclipse update方式安装的麻烦。 link文件样例如: path=d:\\eclipse_plugins\\run-jetty-run
在javaweb项目中嵌入式使用jetty作为web服务器,下载即可运行
gradle的jetty插件使用例子,详细参考:http://blog.csdn.net/xiejx618/article/details/38307289
jetty 服务器使用
文章讲的很详细
jetty嵌入式服务器开发所必须的jar包,本人使用jetty版本为6.1.3,jar包总数为9个,来自jetty:commons-el-1.0.jar,jasper-compiler-5.5.15,jasper-compiler-jdt-5.5.15.jar,jasper-runtime-5.5.15.jar,jetty-...
Jetty配置支持HTTPS以及受信网站证书生成方式