相关的文章太多了,我只按照本身的意思作简单总结。html
参见:web
http://www.cnblogs.com/duanxz/p/3154982.htmlapi
http://www.cnblogs.com/windlaughing/archive/2013/06/07/3125358.htmltomcat
http://www.cnblogs.com/duanxz/p/3154487.html 太过复杂详细。。 谁会这么用呢??app
重要的几点:框架
1 下载相关的jar —— 这个天然的eclipse
2 写本身的server —— 继承Server (jetty提供的Server)。webapp
XmlConfiguration configuration = new XmlConfiguration( // 这个XmlConfiguration是jetty提供的
new FileInputStream(this.xmlConfigPath)); // 这个xmlConfigPath路径即jetty.xml
configuration.configure(this);this
jetty.xml 是jetty框架的基础配置文件(从名字可知一二)。 主要描述了ip、端口、链接池信息、空闲时间等server
web.xml 是servlet的规范,在此时依然有效,依然是用来配置servlet的。—— 相对下者,这个能够理解为 用来配置自定义的servlet 等
webdefault.xml 这个是jetty在提供服务的时候须要注册的自身的一些 基础的配置、启动参数、servlet、listener等, 差很少跟tomcat的配置同样复杂而完整。
3 WebAppContext 顾名思义, 是jetty的web app 上下文环境(很是基础不可或缺的一个接口)。 其提供的几个方法静态方法很重要
setContextPath
setDefaultsDescriptor
setResourceBase
setWar
ContextHandlerCollection handler = new ContextHandlerCollection();
WebAppContext webapp = new WebAppContext();
// WebAppContext 属于handler, extends ServletContextHandler implements WebAppClassLoader.Context
webapp.setContextPath(contextPath); // contextPath至关于一个主机下一个独立的app、 同tomcat一个主机可对应多个contextPath
webapp.setDefaultsDescriptor("./jetty/etc/webdefault.xml");
if (!warDeployFlag) {
webapp.setResourceBase(resourceBase);
webapp.setDescriptor(webXmlPath);
} else {
webapp.setWar(warPath);
}
handler.addHandler(webapp);
super.setHandler(handler);
4 调用Server提供的启动方法便可: super.start() —— 这样就像执行了tomcat的startu.bat同样,
jetty将会解析相关文件,监听相应端口,而后响应请求!
5 部署有两种方式
目录部署 ——经过setResourceBase(resourceBase) 和 setDescriptor(webXmlPath) —— 这二者彷佛是能够分离而无依赖的。因此提供了两个方法。。
war部署 ——经过setWar (里面有包含webXmlPath ,因此不用设置了) 。比较慢, 由于,显然的是——解析WAR文件浪费比较时间
6
org.eclipse.jetty.server.Server 是重中之重。 至关于tomcat的Bootstrapper??
参考 http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/Server.html
提供有:
start
stop
join ?
addBean removeBean之类的 —— 这个有些不太理解。。。
至关之多 ! 可见其对 web程序的控制, 很是的方便灵活 —— 想起就起,想停就停。。。