jetty

 相关的文章太多了,我只按照自己的意思做简单总结。

参见:

http://www.cnblogs.com/duanxz/p/3154982.html

http://www.cnblogs.com/windlaughing/archive/2013/06/07/3125358.html

 http://www.cnblogs.com/duanxz/p/3154487.html 太过复杂详细。。  谁会这么用呢??

重要的几点:

1 下载相关的jar —— 这个自然的

2 写自己的server —— 继承Server (jetty提供的Server)。

 XmlConfiguration configuration = new XmlConfiguration(    // 这个XmlConfiguration是jetty提供的
                    new FileInputStream(this.xmlConfigPath));    // 这个xmlConfigPath路径即jetty.xml
            configuration.configure(this);

jetty.xml 是jetty框架的基础配置文件(从名字可知一二)。 主要描述了ip、端口、连接池信息、空闲时间等

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程序的控制,      非常的方便灵活 ——  想起就起,想停就停。。。

原文地址:https://www.cnblogs.com/FlyAway2013/p/3565562.html