??xml version="1.0" encoding="utf-8" standalone="yes"?>麻豆成人在线观看,99视频在线,波多野结衣一区二区三区http://www.aygfsteel.com/wangxinsh55/category/24824.htmlzh-cnMon, 18 Jul 2016 08:51:56 GMTMon, 18 Jul 2016 08:51:56 GMT60 使用embeded tomcatq行嵌入式javaee开发-启动tomcathttp://www.aygfsteel.com/wangxinsh55/archive/2016/07/18/431229.htmlSIMONESIMONEMon, 18 Jul 2016 06:42:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2016/07/18/431229.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/431229.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2016/07/18/431229.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/431229.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/431229.htmlhttps://www.iflym.com/index.php/code/use-embeded-tomcat-to-javaee-start-tomcat.html
昨天在网上研I了下关于将tomcat嵌入CE序中进行运行,而不是像以前一个web目copy到tomcat中进行运行。之所以这样做的原 因,x因ؓ目部v到客hQ在q行更新的时候,需要手动地q行更新Q再把相应代码copy到tomcatQ然后再q行。运用embeded tomcat可以将目与tomcat分开Q在q行更新Ӟ先用自定义的程序进行自动化更新Q待更新完毕之后Q再启动tomcatQ或其它 javaee容器Q进行项目运行?

     q样做的最l效果就是修改了目的运行方式。原先的q行方式是以tomcatZ心,由tomcat来启动和l止目Q现在是由我们的启动E序 Z心,由启动程序来负责启动和终止项目。就相当于现在流行的csE序一P有单独的启动脚本Q在启动时进行环境预初始化,更新E序以及其它操作Q待完成 之后再进行最l的目启动?/p>

     q篇主要讲解如何使用embeded tomcat在代码中q行启动和终止。网上的一般文章均为tomca5.x来做Q这里用了最新的tomcat7Q因为tomcat7为embeded开 发,单独发布了org.apache.tomcat.embed包,以进行独立的embed开发。以下是相应的maven?/p>

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>7.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-util</artifactId>
            <version>7.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>7.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-logging-juli</artifactId>
            <version>7.0.2</version>
        </dependency>

    使用了embed包中的core包,以及用于~译jsp的jasper包,然后是工L以及q行上场记录的logging-juli包。开始写代码Q?/p>

1
2
3
4
5
6
7
//讄工作目录
        String catalina_home = "d:/";
        Tomcat tomcat = new Tomcat();
        tomcat.setHostname("localhost");
        tomcat.setPort(startPort);
        //讄工作目录,其实没什么用,tomcat需要用这个目录进行写一些东?/code>
        tomcat.setBaseDir(catalina_home);

    上面使用了TomcatcLq行启动c,在tomcat7以前均是使用一个叫EmbedcLq行启动Q在tomcat7之后Qembedc被不徏 议用,而徏议用新的TomcatcLq行启动了。然后设|主机名Q端口,再设|一个工作目录。这个工作目录可以是L目录Q主要是tomcat需要这 个目录来记录一些东西,比如记录word信息Q日志信息(如果配置了日志的话)Q以及时文件存储等?/p>

1
2
3
4
5
6
7
8
//讄E序的目录信?/code>
        tomcat.getHost().setAppBase("e:/");
        // Add AprLifecycleListener
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        server.addLifecycleListener(listener);
        //注册关闭端口以进行关?/code>
        tomcat.getServer().setPort(shutdownPort);

    上面的代码,首先讄我们的项目程序所在的appbaseQ即N目代码的地方。在通常的tomcat配置中,q个目录一般是webapps。接 着讄一个listenerQ这个listener主要是负责启动一些比如html native支持E序以及ipv6{信息配|(可以忽略Q。接着是配|一个关闭的注册端口Q当向这个端口发送信息时Q就可以辑ֈ关闭tomcat的目?Q后面会Ԍ?/p>

1
2
3
4
5
6
7
8
9
//加蝲上下?/code>
        StandardContext standardContext = new StandardContext();
        standardContext.setPath("/aa");//contextPath
        standardContext.setDocBase("aa");//文g目录位置
        standardContext.addLifecycleListener(new Tomcat.DefaultWebXmlListener());
        //保证已经配置好了?/code>
        standardContext.addLifecycleListener(new Tomcat.FixContextListener());
        standardContext.setSessionCookieName("t-session");
        tomcat.getHost().addChild(standardContext);

    我们单独使用了一个Context来ؓq个hostd上下文,tomcat本n提供一个方法tomcat.addWebҎ来添加项目包Q不q?׃q里需要单独设|一个tomcat的sessionNameQ所以用与与tomcat.addWeb实现cM的方法来d一个项目包?br />     以上代码中有两个需要注意的listenerQ一个是DefaultWebXmlListenerQ这个是由tomcat加蝲一些默认的配置?息,比如jspServletQ以及一些繁复的mime/type信息Q加上这个,׃需要我们自己去写这么多的配|,因ؓ每个目都需要这些。这个配|?与tomcat目录下的conf/web.xml中的配置一P只不q这里是代码化了。第二个是FixContextListenerQ这个主要是在项?部v完后Q将q个上下文设|ؓconfiguredQ表C已l配|好了(不然Qtomcat启动时会报错Q即相应上下文还未配|好Q?br />     配置OK了之后,是启动tomcat了:

1
2
tomcat.start();
        tomcat.getServer().await();

    启动tomcatQƈ让tomcat在关闭端口上监听。如果没有最后一句,E序直接结束,保证监听之后Qtomcat一直监听关闭事Ӟ待有关闭事g之后才结束当前程序。所以如果想要关闭当前的tomcatQ只需要向关闭端口发送一些信息即可:

1
2
3
4
5
6
7
8
9
private static void shutdown() throws Exception {
        Socket socket = new Socket("localhost", shutdownPort);
        OutputStream stream = socket.getOutputStream();
        for(int i = 0;i < shutdown.length();i++)
            stream.write(shutdown.charAt(i));
        stream.flush();
        stream.close();
        socket.close();
    }

    q样卛_辑ֈ关闭tomcat的目的?/p>

     实际上看整个目代码Q项目代码的q行Q就是一个配|一个基的server.xmlQ即tomcat目录下的 conf/server.xml)Q先配置q行端口Q关闭监听端口;然后配置q行的host以及d一个上下文contextQ最后就开始运行ƈ开始监 听。对照这个程序,再看一下server.xml中的配置信息Q就很容易明白以上这D代码了?/p>



SIMONE 2016-07-18 14:42 发表评论
]]>
tomcat7升至Tomcat8后兼Ҏ问题修?/title><link>http://www.aygfsteel.com/wangxinsh55/archive/2015/04/09/424255.html</link><dc:creator>SIMONE</dc:creator><author>SIMONE</author><pubDate>Thu, 09 Apr 2015 09:35:00 GMT</pubDate><guid>http://www.aygfsteel.com/wangxinsh55/archive/2015/04/09/424255.html</guid><wfw:comment>http://www.aygfsteel.com/wangxinsh55/comments/424255.html</wfw:comment><comments>http://www.aygfsteel.com/wangxinsh55/archive/2015/04/09/424255.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wangxinsh55/comments/commentRss/424255.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wangxinsh55/services/trackbacks/424255.html</trackback:ping><description><![CDATA[Tomcat7默认的url串参数值是ios-8859-1~码Q而Tomcat8默认的是UTF-8?br />另外Tomcat8对写入cookie的字W串限制更严|不允怋? q样D无法写Cookie的path路径?br /><br />目前发现能解决的办法有两U?br />Ҏ一?br />server.xml文gConnectorl点d URIEncoding="iso-8859-1" 属?br /><br /><br />Ҏ二?br /><div>catalina.properties配置d配置属?br /><div>#讄为true则默认用iso-8859-1~码Q否则默认是UTF-8~码Q参考Tomcat文<br />#http://tomcat.apache.org/tomcat-8.0-doc/config/http.html<code>  URIEncoding</code> 属性部?br />#http://tomcat.apache.org/tomcat-8.0-doc/config/systemprops.html<code>   org.apache.catalina. STRICT_SERVLET_COMPLIANCE</code> 属性部?br />org.apache.catalina.STRICT_SERVLET_COMPLIANCE=true<br /><br />#Cookie的path限制修改Qfalse允许使用/ 参考Tomcat文<br />#http://tomcat.apache.org/tomcat-8.0-doc/config/systemprops.html<br /><div>org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR=false</div></div></div><img src ="http://www.aygfsteel.com/wangxinsh55/aggbug/424255.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wangxinsh55/" target="_blank">SIMONE</a> 2015-04-09 17:35 <a href="http://www.aygfsteel.com/wangxinsh55/archive/2015/04/09/424255.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat的reloadable参数的意?/title><link>http://www.aygfsteel.com/wangxinsh55/archive/2011/05/31/351449.html</link><dc:creator>SIMONE</dc:creator><author>SIMONE</author><pubDate>Tue, 31 May 2011 08:55:00 GMT</pubDate><guid>http://www.aygfsteel.com/wangxinsh55/archive/2011/05/31/351449.html</guid><wfw:comment>http://www.aygfsteel.com/wangxinsh55/comments/351449.html</wfw:comment><comments>http://www.aygfsteel.com/wangxinsh55/archive/2011/05/31/351449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wangxinsh55/comments/commentRss/351449.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wangxinsh55/services/trackbacks/351449.html</trackback:ping><description><![CDATA[<div><div> <a id="viewpost1_TitleUrl" href="../../liyoubiggo/archive/2008/09/07/227583.html">tomcat的reloadable参数的意?/a> </div> <span style="word-spacing: 0px; font-family: verdana; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 22px; font-size-adjust: none; font-stretch: normal; text-transform: none; color: #000000; text-indent: 28px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2;">开启了Tomcat的reloadable=true,那么每当相关文g改变ӞTomcat会停止web appq攑ֆ?然后重新加蝲web app.q实在是个浩大的工程?/span><br />        另外|上有一文章是关于在Tomcatq行动态重载类Q下面是该文章的内容<br />         <span style="word-spacing: 0px; font-family: verdana; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-size-adjust: none; font-stretch: normal; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; text-align: left; orphans: 2; widows: 2;"><span id="Post.ascx_ViewPost_PreviousAndNextEntriesUp"><a style="color: #000000; text-decoration: none;" ><br /> </a></span> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">Z么写q篇文档Q?/p> </li></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">?用过hibernate, spring或其他大型组Ӟ写过50个类以上的网l应用程?web application)的开发者应该知道,当系l中有很多类Ӟ如果开启了Tomcat的reloadable=true,那么每当相关文g改变 ӞTomcat会停止web appq攑ֆ?然后重新加蝲web app.q实在是个浩大的工程?br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">所以我L在想如果能有只重载某几个cȝ功能Q将极大的满xq个x调试狂?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">d我在论坛上发帖,才发现已l有一些应用服务器h了这个功能,比如WebLogic, WebSphere, {等。好像还有一个很L名字Q叫开发模式。看来我q是孤陋寡闻了点?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">当然很多人都是在Tomcat上开发,包括我。我很喜Ƣ它的轻,那些大内存和高CPU消耗的应用服务器不愧ؓg杀手,没理׃改进Tomcat :)?/p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="2"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">最l实现功?/p> </li></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">我没有时间去研究Tomcat的文件监听机Ӟ也没旉L他写?#8221;开发模?#8221;q么完整的功能,我最l实现的是,实现重蝲功能的测试jspQ-很抱歉我q是没办法写得更完整。当Ӟ你可以在q个基础上进行改q?/p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="3"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">阅读ȝ</p> </li></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">阅读本文Q你应该具备以下知识</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">jvm 规范有关cd载器的章?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><a style="color: #336699; text-decoration: none;" >http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html</a></p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">Tomcat cd载机?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><a style="color: #336699; text-decoration: none;" >http://www.huihoo.org/apache/tomcat/</a></p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">java 反射机制</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><a style="color: #336699; text-decoration: none;" >http://java.sun.com/docs/books/tutorial/reflect/</a></p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">ant</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><a style="color: #336699; text-decoration: none;" >http://ant.apache.org/</a></p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">(好象该网址被不定时锁Q有时能上,有时不能)</p> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">最好在你的电脑上安装ant,因ؓTomcat源码包用ant从互联网获得依赖包。不q我也是修改了一个错误才使它完全~译通过?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">当然Q你也可以用其他IDE工具查ƈd依赖包,在IDE中,其实你只需要添加jar直到使org.apache.catalina.loader.WebappClassLoader无错卛_?/p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="4"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">修改q程</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">说明</p> </li></ol> </li></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>新添加的代码h加到java文g的末,因ؓ我在说明行数的时候,量W合原始行数</strong></p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="2"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">web appcd载器</p> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">在Tomcat中,org.apache.catalina.loader.WebappClassLoader是web app的类加蝲器,所以需要修改它实现重蝲功能?/p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="3"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">资源列表</p> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">在WebappClassLoader中,有一个Mapcd属性resourceEntriesQ它记蝲了web app中WEB-INF/classes目录下所加蝲的类Q因此当我们需要重载一个类Ӟ我们需要先它在resourceEntries里删除,我编写了一个方法方便调用:</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>public</strong> <strong>boolean</strong> removeResourceEntry(String name) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">     <strong>if</strong> (resourceEntries.containsKey(name)) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">         resourceEntries.remove(name);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">         <strong>return</strong> <strong>true</strong>;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">     }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">     <strong>return</strong> <strong>false</strong>;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">}</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="4"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">是否重蝲标志</p> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">让WebappClassLoader需要知道加载一个类是否使用重蝲的方式。所以我建立一个boolean cd的属性和实现它的getter/setterҎQ?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>private</strong> <strong>boolean</strong> isReload = <strong>false</strong>;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">      <strong>public</strong> <strong>boolean</strong> isReload() {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">          <strong>return</strong> isReload;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">      }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">      <strong>public</strong> <strong>void</strong> setReload(<strong>boolean</strong> isReload) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">          <strong>this</strong>.isReload = isReload;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">      }</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="5"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">动态类加蝲?/p> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">Ҏjvmcd载器规范Q一个类加蝲器对象只能加载一个类1ơ,所以重载实际上是创建出另一个类加蝲器对象来加蝲同一个类。当Ӟ我们不需要再创徏一个WebappClassLoaderQ他太大而且加蝲规则很复杂,不是我们惌的,所以我们创Z个简单的cd载器corg.apache.catalina.loader.DynamicClassLoaderQ?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>package</strong> org.apache.catalina.loader;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><strong>import</strong> java.net.URL;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><strong>import</strong> java.net.URLClassLoader;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><strong>import</strong> java.security.CodeSource;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><strong>import</strong> java.util.*;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">/**</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">* 动态类加蝲?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">*</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">* <strong>@author </strong>peter</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">*</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">*/</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><strong>public</strong> <strong>class</strong> DynamicClassLoader <strong>extends</strong> URLClassLoader {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    /* 父类加蝲?nbsp;*/</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    <strong>private</strong> ClassLoader parent = <strong>null</strong>;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    /* 已加载类名列?nbsp;*/</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    <strong>private</strong> List classNames = <strong>null</strong>;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    /**</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * 构造器</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    *</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * <strong>@param </strong>parent</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * 父类加蝲器,q里传入的是WebappClassLoader</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    */</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    <strong>public</strong> DynamicClassLoader(ClassLoader parent) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>super</strong>(<strong>new</strong> URL[0]);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        classNames = <strong>new</strong> ArrayList();</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>this</strong>.parent = parent;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    /**</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * 从类的二q制数据中加载类.</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    *</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * <strong>@param </strong>name</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * cd</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * <strong>@param </strong>classData</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * cȝ二进制数?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * <strong>@param </strong>codeSource</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * 数据来源</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * <strong>@return </strong>成功加蝲的类</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * <strong>@throws </strong>ClassNotFoundException</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * 加蝲p|抛出未找到此cd?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    */</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    <strong>public</strong> Class loadClass(String name, <strong>byte</strong>[] classData, CodeSource codeSource)<strong> throws</strong> ClassNotFoundException {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>if</strong> (classNames.contains(name)) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            // System.out.println("此类已存在,调用 loadClass Ҏ加蝲.");</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>return</strong> loadClass(name);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        } <strong>else</strong> {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            // System.out.println("新类, 记录到类名列表,q用cd义方法加载类");</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            classNames.add(name);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>return</strong> defineClass(name, classData, 0, classData.length, codeSource);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    /* *</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * 重蝲此方法,当要加蝲的类不在cd列表中时Q调用父cd载器Ҏ加蝲.</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    * @see java.lang.ClassLoader#loadClass(java.lang.String)</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    */</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    <strong>public</strong> Class loadClass(String name) <strong>throws</strong> ClassNotFoundException {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>if</strong> (!classNames.contains(name)) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            //System.out.println("不在cd列表中,调用父类加蝲器方法加?);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>return</strong> parent.loadClass(name);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>return</strong> <strong>super</strong>.loadClass(name);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">    }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">}</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="6"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">在webappClassLoader中添加DynamicClassLoader</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">d属?/p> </li></ol> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>private</strong> DynamicClassLoader dynamicClassLoader = <strong>new</strong> DynamicClassLoader(<strong>this</strong>);</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="2"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">d重徏ҎQ以侉K要再ơ重载时替换掉上ơ的cd载器对象</p> </li></ol></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>public</strong> <strong>void</strong> reCreateDynamicClassLoader() {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                dynamicClassLoader = <strong>new</strong> DynamicClassLoader(<strong>this</strong>);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            }</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="7"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">修改调用?/p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">W?32行,公开findClassҎ</p> </li></ol> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>public</strong> Class findClass(String name) <strong>throws</strong> ClassNotFoundException {</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="2"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">W?569行,d如下一行代码?/p> </li></ol></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>if</strong> (isReload) removeResourceEntry(name);</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="3"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">W?577行,q里好像是一个bugQ具体原因我忘了-_-||</p> </li></ol></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>if</strong> ((entry == <strong>null</strong>) || (entry.binaryContent == <strong>null</strong>))</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">改ؓ</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>if</strong> ((entry == <strong>null</strong>) || (entry.loadedClass == <strong>null</strong> && entry.binaryContent == <strong>null</strong>))</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="4"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">W?633~1636?/p> </li></ol></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>if</strong> (entry.loadedClass == <strong>null</strong>) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">                clazz = defineClass(name, entry.binaryContent, 0, entry.binaryContent.length,</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">                    codeSource);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">            改ؓ</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">            <strong>byte</strong>[] classData = <strong>new</strong> <strong>byte</strong>[entry.binaryContent.length];</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            System.arraycopy(entry.binaryContent, 0, classData, 0,</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            classData.length);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>if</strong> (entry.loadedClass == <strong>null</strong>) {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                clazz = isReload ?</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                    dynamicClassLoader.loadClass(name,</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                    classData, codeSource) :</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                    defineClass(name,</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                    classData, 0, classData.length, codeSource);</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="8"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">试代码</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">test.jsp</p> </li></ol> </li></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">我测试用的jsp?CATALINA_HOME/webapps/ROOT/test.jspQ由于webapp里面q不会显式加载tomcat的核心类Q所以我们需要用反射代码调用WebappClassLoader的方法。代码如下:</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><%</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">ClassLoader loader = (Thread.currentThread().getContextClassLoader());</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">Class clazz = loader.getClass();</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">java.lang.reflect.Method setReload = clazz.getMethod("setReload", <strong>new</strong> Class[]{<strong>boolean</strong>.<strong>class</strong>});</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">java.lang.reflect.Method reCreate = clazz.getMethod("reCreateDynamicClassLoader", <strong>null</strong>);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">java.lang.reflect.Method findClass = clazz.getMethod("findClass", <strong>new</strong> Class[]{String.<strong>class</strong>});</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">reCreate.invoke(loader, <strong>null</strong>);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">setReload.invoke(loader, <strong>new</strong> Object[]{<strong>true</strong>});</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">Class A = (Class)findClass.invoke(loader, <strong>new</strong> Object[]{"org.AClass"});</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">setReload.invoke(loader, <strong>new</strong> Object[]{<strong>false</strong>});</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">A.newInstance();</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">// 如果你用下面这行代码,当重~译cLQ请E微修改一下调用它的jspQ让jsp也重新编?/p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">//org.AClass a = (org.AClass)A.newInstance();</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">// 下面q些代码是测试当一个类不在DynamicClassLoadercd列表时的反应</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">//a.test();</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">//java.lang.reflect.Method test = a.getClass().getMethod("test", null);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">//test.invoke(a, null);</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">%></p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="2"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">org.AClass</p> </li></ol></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>package</strong> org;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>public</strong> <strong>class</strong> AClass {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>public</strong> AClass() {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                // 修改输出内容认Tomcat重新加蝲了类</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                System.out.println("AClass v3");</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>public</strong> <strong>void</strong> createBClass() {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                <strong>new</strong> BClass();</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        }</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="3"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">org.BClass</p> </li></ol></ol></ol> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left"><strong>package</strong> org;</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;"><br /> </p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        <strong>public</strong> <strong>class</strong> BClass {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            <strong>public</strong> BClass() {</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                //修改输出内容认Tomcat重新加蝲了类</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">                System.out.println("BClass v1");</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">            }</p> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;">        }</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;" start="9"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">试步骤</p> <ol style="margin: 5px 0px 5px 35px; padding: 0px; list-style-type: none;"><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">按照上述步骤修改Tomcat源码q编译?/p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">用winzip/winrar/file-roller打开$CATALINA_HOME/server/lib/catalina.jar。把前面~译完成后的org.apache.catalina.loader目录下的class文g覆盖jar中同名文件?/p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">~译org.AClass和org.BClass</p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">启动Tomcatq在览器中打开试http://localhost:8080/test.jsp</p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">修改org.AClass中的System.out.println();语句q~译cR?/p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">按下F5按键h览器?/p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">查看Tomcat控制台是否输Z不同的语句?</p> </li><li style="margin: 0px; padding: 2px 0px; list-style-type: decimal;"> <p style="margin: 1em 0px 0.5em; padding: 0px; font-size: 14px; text-indent: 2em; line-height: 22px;" align="left">Good Luck! :)))</p> </li></ol> </li></ol></ol> </span> </div><img src ="http://www.aygfsteel.com/wangxinsh55/aggbug/351449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wangxinsh55/" target="_blank">SIMONE</a> 2011-05-31 16:55 <a href="http://www.aygfsteel.com/wangxinsh55/archive/2011/05/31/351449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> tomcat定时重启与服务注册方?http://www.aygfsteel.com/wangxinsh55/archive/2010/01/27/310929.htmlSIMONESIMONEWed, 27 Jan 2010 05:15:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2010/01/27/310929.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/310929.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2010/01/27/310929.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/310929.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/310929.html保存以下脚本成tomcat.batQ计划Q务指定每?Ҏ行该脚本
@echo off
net stop tomcat5
rem ping 20个包Q实现g时功?br /> ping 127.0.0.1 -n 20
net start tomcat5
 
 
注意q里的tomcat5是tomcat在windows的服务名Q注册服务的Ҏ如下Q?br /> 扑ֈtomcat安装目录bin子目录下的service.bat
在命令行里执行:
service.bat install
则自动安装服务?br /> 定时重启SQL Server
net stop mssqlserver
net start mssqlserver
tomcat产生垃圾~存文g的处理与tomcat的定旉?/p>

׃E序中用了jtds驱动来连接数据库?br /> 一D|间后Q我发现tomcat的temp文g夹内jtds*.tmp文g(形如jtds424647.tmp)来多Q容量也来大。有一ơ清理时Q据然有几个G多,严重的媄响了pȝ的运行速度?/p>

解决措施:

如果是linuxpȝ
可以指定启动?Djava.io.tmpdir=/tmp
q个目录pȝ会用cron脚本自动清理文g

如果是windowsQ需要定期清理tomcat的tmp文g

可以用windows自带的定时Q务器建立如下delTmp.bat的文?/p>

@echo off

 

:start

::启动q程Q切换目?/p>

set pwd=%cd%

cd %1

echo 工作目录是:& chdir

 

:clean

::d理过E,执行清理工作

@echo on

rem @for  /r %%c in (.log) do @if exist %%c ( rd /s /q %%c & echo     删除目录%%c)

@echo off

@del logs\*.log

@del temp\*.tmp

del /f /s /q E:\osaplatform\WEB-INF\logs\*.log.*-*

echo "当前目录下的log信息已清?

goto end

 

:noclean

::分支q程Q取消清理工?/p>

echo "log信息清楚操作已取?

goto end

 

:end

::退出程?/p>

cd "%pwd%"

REM pause

 

 

Tomcat׃q行的时间过镉K成内存不宜释放Q导致运行性能的降低,定时重启tomcat有利于提升系l的性能Q?/p>

首先建立如下的bat文g

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_06

E:\tomcat6_hb\bin\service.bat install Tomcat604

注册为windows服务

然后在徏立tomcat.batQƈ此文g攑ֈwindows定期d?/p>

@echo off

net stop tomcat5

rem ping 20个包Q实现g时功?/p>

ping 127.0.0.1 -n 20

net start tomcat5

如果需要解除服务,则徏立如下文Ӟ直接执行卛_

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_06

E:\tomcat6_hb\bin\service.bat remove Tomcat604



SIMONE 2010-01-27 13:15 发表评论
]]>
解决Tomcat下Context重复启动(?http://www.aygfsteel.com/wangxinsh55/archive/2009/03/11/259229.htmlSIMONESIMONEWed, 11 Mar 2009 14:09:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2009/03/11/259229.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/259229.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2009/03/11/259229.html#Feedback1http://www.aygfsteel.com/wangxinsh55/comments/commentRss/259229.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/259229.html配置了个定时抓取dQ结果L抓取三次
从Tomcat的log上看到该d所在的Context有三ơ启动的q程Q计划Q务也被创Z三次

问题原来出在Host的appBase讄上,原来的设|是q样?/p>

<Host name="www.xxx.com" appBase="/usr/local/projects/xxx/"
  
unpackWARs="false" autoDeploy="true"
  
xmlValidation="false" xmlNamespaceAware="false">
  
<Context docBase="web" path="" reloadable="true" workDir="work">
  
<!-- Others -->
  
</Context>
</Host>

<Host name="admin.xxx.com" appBase="/usr/local/projects/xxx/"
  
unpackWARs="false" autoDeploy="true"
  
xmlValidation="false" xmlNamespaceAware="false">
  
<Context docBase="admin" path="" reloadable="true" workDir="work">
  
<!-- Others -->
  
</Context>
</Host>

Ҏ不设|appBaseQ只Ҏ定的Context讄docBaseok?/p>

<Host name="www.xxx.com" appBase=""
  
unpackWARs="false" autoDeploy="true"
  
xmlValidation="false" xmlNamespaceAware="false">
  
<Context docBase="/usr/local/projects/xxx/web" path="" reloadable="true" workDir="work">
  
<!-- Others -->
  
</Context>
</Host>

<Host name="admin.xxx.com" appBase=""
  
unpackWARs="false" autoDeploy="true"
  
xmlValidation="false" xmlNamespaceAware="false">
  
<Context docBase="/usr/local/projects/xxx/admin" path="" reloadable="true" workDir="work">
  
<!-- Others -->
  
</Context>

Z么不讄appBaseOK来呢Q?/p>

因ؓ讄了appBase׃自动d载底下所有的目


SIMONE 2009-03-11 22:09 发表评论
]]>
tomcat?׃nsession (摘自|上Q没有具体验证,如果哪位验证了,请告知一下谢?http://www.aygfsteel.com/wangxinsh55/archive/2009/03/06/258199.htmlSIMONESIMONEFri, 06 Mar 2009 06:23:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2009/03/06/258199.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/258199.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2009/03/06/258199.html#Feedback3http://www.aygfsteel.com/wangxinsh55/comments/commentRss/258199.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/258199.html

我们采取的是集中理的办法。主要技术:

1.讄Context 的crossContext="true"Q得各个web应用的servletcontext是可以互访的

       <Host name="localhost" appBase="webapps"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
<Context path="/SessionManager" reloadable="true" crossContext="true"></Context>
<Context path="/SessionManagerTest1" reloadable="true" crossContext="true"></Context>
<Context path="/SessionManagerTest2" reloadable="true" crossContext="true"></Context>

2.d讄cookiesQ设|jsessionid׃n的session的idQ统一利用requestsessionid在指定的一? servletcontext里的一个map查找对于的sessionQ需要存取attribute都对取得的session操作

3.用监听器监听属性的失效



Tomcat集群之Session复制配置 分n

因ؓ最q的目要用到多web服务器实现访问负载和集群Q负载调度用的是LVSQ而非apache的负载调度,因ؓ在高讉K量和大ƈ发量的时候LVS? 性能比APACHE好。然后在web服务器上是用tomcat5.5.25做应用服务器Q对于tomcat的集有两种方式Q这个主要是针对 session而言的。一U就是sticky模式Q即黏性会话模式;另外一U就是session复制模式了。所谓sticky模式是说同一个用L讉K h都被zN到同一个tomcat实例上,q样我们无d多台服务器之间实现session׃n了,q是其好处,不好的地方就是不能实? failureover了,一但用戯问的机器挂掉Q那么其session׃丢失。而session复制模式可以很好的解决failureover? 问题Q即使某一台web服务器挂掉了Q用Lhq会被负载到其他的web服务器上Q而且session也被复制了,q样对用戯言像是在同一台机器上 操作一P不好的地方就是session复制需要系l资源和|络的开销Q尤其是当web服务器多的时候或session里存储的数据量大的时候,q点会 比较的明显(不过自己q没有做q方面的试Q?

针对q两U方式的弊端和好处,我们可以采用两U方式结合的方式来达到更好的效果Q那 是sticky+session复制模式了。用Lh按照 sticky方式被分发到同一个web服务器上Q同时tomcat在后台做异步复制Q非同步Qsession到其他web服务器,q样我们使用 sticky的简便性,同时又有了一定的定w能力?

下面我就自qtomcat集群配置l验跟大家分享一下,呵呵。现在想来,其实tomcat的集配|真的是非常单,几乎不需要改什么东西了。我今天在windows上用一台机器来跑两个tomcat实例Q下面是一些基条gQ?
1.两个tomcat的目录分别ؓQd:\apache-tomcat-5.5.25-node1和d:\apache-tomcat-5.5.25-node2
2.在每个tomcat目录下的conf\Catalina\localhost目录下徏立一个ROOT.xml文gQ其内容为:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <Context docBase="D:/mywebapps/test1"
3 privileged="true" antiResourceLocking="false" antiJARLocking="false" distributable="true">
4 </Context>

3.修改apache-tomcat-5.5.25-node1的connector端口?091Q修改apache-tomcat-5.5.25-node2的connector的端口ؓ8092Q这hZ避免在同一机器上同时启动时造成讉K端口冲突Q?
4.修改apache-tomcat-5.5.25-node2的Server端口?006Q与apache-tomcat-5.5.25-node1的Server端口8005不一P也是避免两个tomcat实例启动旉成E序端口的冲H问题;
5.修改apache-tomcat-5.5.25-node2的AJP/1.3的端口ؓ8019或其他非8009Q默认)的端口,也是Z避免与apache-tomcat-5.5.25-node1的AJP/1.3端口冲突Q?

q? P我们可以保证每一个tomcat单独启动旉可以提供D:/mywebapps/test1的web服务Q注意是单个启动哦,然后分别启动 apache-tomcat-5.5.25-node1和apache-tomcat-5.5.25-node2后,输入如下地址分别q行讉K你的web 应用Q?
apache-tomcat-5.5.25-node1的访问地址Qhttp://localhost:8091/你的面地址
apache-tomcat-5.5.25-node2的访问地址Qhttp://localhost:8092/你的面地址
如果你的tomcat没能成功的提供服务,那么你就需要查看一下是否tomcat部v成功了。注意这里的D:/mywebapps/test1是你的web应用的物理\径了Q可以随意修攏V下面就开始对server.xml文g的配|了?

扑ֈapache-tomcat-5.5.25-node1目录下的server.xml文gQ打开q找到配|Engine的位|,我们在最后加?jvmRoute="node1"Q表C个tomcat的实例名UCؓnode1。修改前后的Ҏ如下Q?

修改前:
<Engine name="Catalina" defaultHost="localhost">
修改后:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">

? 后找到Cluster标签Qƈ取消它的注释卛_Q无dM修改。同P我们修改apache-tomcat-5.5.25-node2下的 server.xml文gQ修改jvmRoute="node2"Q然后也是注释掉Cluster标签Q注意,然后q要修改Cluster标签下的 Receiver标签的tcpListenPort端口P我们改ؓ4002Q默认的?001Q,q个是ؓ了避免两个tomcat实例同时启动旉成? H?

通过上面的配|后Q我们两个tomcat已经配置完毕Qƈ且可以完成集Q务了。注意启动的时候不能直接双dbing目录下的 startup.bat文gQ我们还需要ؓ每一个tomcat讄环境变量Q分别在apache-tomcat-5.5.25-node1? apache-tomcat- 5.5.25-node2的根目录下编写一个bat文gQ内容如下:

apache-tomcat-5.5.25-node1目录下的startup_node1.bat内容Q?
set CATALINA_HOME=d:\apache-tomcat-5.5.25-node1
bin/startup.bat

apache-tomcat-5.5.25-node2目录下的startup_node2.bat内容Q?
set CATALINA_HOME=d:\apache-tomcat-5.5.25-node2
bin/startup.bat

然后分别q行q两批处理文件即可正常启动tomcat了。我们先启动node1Q双击startup_node1.bat启动node1。我们可以在H口的最上面看到如下的输Z息:
2008-1-4 19:12:24 org.apache.catalina.cluster.tcp.SimpleTcpCluster start
信息: Cluster is about to start
2008-1-4 19:12:25 org.apache.catalina.cluster.tcp.ReplicationTransmitter start
信息: Start ClusterSender at cluster Catalina:type=Cluster,host=localhost with n
ame Catalina:type=ClusterSender,host=localhost
2008-1-4 19:12:25 org.apache.catalina.cluster.mcast.McastServiceImpl setupSocket

信息: Setting cluster mcast soTimeout to 500
2008-1-4 19:12:25 org.apache.catalina.cluster.mcast.McastService start
信息: Sleeping for 2000 milliseconds to establish cluster membership
2008-1-4 19:12:27 org.apache.catalina.cluster.mcast.McastService registerMBean
信息: membership mbean registered (Catalina:type=ClusterMembership,host=localhos
t)
2008-1-4 19:12:27 org.apache.catalina.cluster.deploy.FarmWarDeployer start
信息: Cluster FarmWarDeployer started.
2008-1-4 19:12:29 org.apache.catalina.cluster.session.DeltaManager start
信息: Starting clustering manager...:
2008-1-4 19:12:29 org.apache.catalina.cluster.session.DeltaManager start
信息: Register manager to cluster element Host with name localhost
2008-1-4 19:12:29 org.apache.catalina.cluster.session.DeltaManager start
信息: Starting clustering manager at
2008-1-4 19:12:29 org.apache.catalina.cluster.session.DeltaManager getAllCluster
Sessions
信息: Manager []: skipping state transfer. No members active in cluster group.

q表明我们的tomcat集群已经正常启动了。然后我们再q行apache-tomcat-5.5.25-node2目录下的startup_node2.bat以启动node2。然后我们可以可以在H口的最上方看到如下的信息输出:
2008-1-4 19:16:32 org.apache.catalina.cluster.tcp.SimpleTcpCluster start
信息: Cluster is about to start
2008-1-4 19:16:32 org.apache.catalina.cluster.tcp.ReplicationTransmitter start
信息: Start ClusterSender at cluster Catalina:type=Cluster,host=localhost with n
ame Catalina:type=ClusterSender,host=localhost
2008-1-4 19:16:32 org.apache.catalina.cluster.mcast.McastServiceImpl setupSocket

信息: Setting cluster mcast soTimeout to 500
2008-1-4 19:16:32 org.apache.catalina.cluster.mcast.McastService start
信息: Sleeping for 2000 milliseconds to establish cluster membership
2008-1-4 19:16:32 org.apache.catalina.cluster.tcp.SimpleTcpCluster memberAdded
信息: Replication member added:org.apache.catalina.cluster.mcast.McastMember[tcp
://192.168.1.227:4001,catalina,192.168.1.227,4001, alive=245203]
2008-1-4 19:16:34 org.apache.catalina.cluster.mcast.McastService registerMBean
信息: membership mbean registered (Catalina:type=ClusterMembership,host=localhos
t)
2008-1-4 19:16:34 org.apache.catalina.cluster.deploy.FarmWarDeployer start
信息: Cluster FarmWarDeployer started.
2008-1-4 19:16:35 org.apache.catalina.cluster.session.DeltaManager start
信息: Starting clustering manager...:
2008-1-4 19:16:35 org.apache.catalina.cluster.session.DeltaManager start
信息: Register manager to cluster element Host with name localhost
2008-1-4 19:16:35 org.apache.catalina.cluster.session.DeltaManager start
信息: Starting clustering manager at
2008-1-4 19:16:35 org.apache.catalina.cluster.session.DeltaManager getAllCluster
Sessions
警告: Manager [], requesting session state from org.apache.catalina.cluster.mcas
t.McastMember[tcp://192.168.1.227:4001,catalina,192.168.1.227,4001, alive=248203
]. This operation will timeout if no session state has been received within 60 s
econds.
2008-1-4 19:16:35 org.apache.catalina.cluster.session.DeltaManager waitForSendAl
lSessions

h意node2H口输出的不同颜色部分,q个已经表示node2节点和node2节点联系上了。我们再回过来看node1H口的输Z息,发现多出了如下的信息Q?
2008-1-4 19:16:34 org.apache.catalina.cluster.tcp.SimpleTcpCluster memberAdded
信息: Replication member added:org.apache.catalina.cluster.mcast.McastMember[tcp
://192.168.1.227:4002,catalina,192.168.1.227,4002, alive=0]
q? 表明node1也已l侦听到了node2Q两个tomcat服务器已l徏立了联系。然后我们访问node1的一个地址AQ假设这个地址A往 session里设|一个属性,然后我们再在同一H口中访问node2的一个地址BQ假设B是从session里读取这个属性,我们会发现B地址实得到 了这个刚刚我们在node1上设|进ȝ倹{这里要特别注意的是Q我们两个地址的分别访问必L在同一个窗口中Q因为我们没有做前端的web负蝲Q所以 用不同的H口q行讉K会出C同的session(因ؓ端口号不一?也就D讉K地址不一样了)Q这样就D无法查看的问题?br />


SIMONE 2009-03-06 14:23 发表评论
]]>
Tomcat 配置集锦http://www.aygfsteel.com/wangxinsh55/archive/2008/03/12/185627.htmlSIMONESIMONEWed, 12 Mar 2008 03:10:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2008/03/12/185627.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/185627.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2008/03/12/185627.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/185627.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/185627.html阅读全文

SIMONE 2008-03-12 11:10 发表评论
]]>
tomcat6路径配置心得http://www.aygfsteel.com/wangxinsh55/archive/2007/08/11/136122.htmlSIMONESIMONESat, 11 Aug 2007 15:22:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2007/08/11/136122.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/136122.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2007/08/11/136122.html#Feedback2http://www.aygfsteel.com/wangxinsh55/comments/commentRss/136122.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/136122.html在tomcat6路径配置中,要通过对TOMCAT_HOME\conf\server.xml中的<Host></Host>标签中进行设|。具体是q样的:

<Host name="localhost"  appBase="E:\JavaProject\eclipse33Project\test"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

<Host>

q样站点设|到E:\JavaProject\eclipse33Project\test目录下边。这旉认的|站根目录是ROOT。如果需要设|其它的虚拟目录Q需要在TOMCAT_HOME/conf/[enginename]/[hostname]/[|站根目录名].xml讄?br>如在TOMCAT_HOME/conf/Catalina/localhost/WebRoot.xml下加如下内容Q?/font>
<Context path="/WebRoot" docBase="WebRoot" debug="0" reloadable="true">
</Context>
也可以不需要设|WebRoot.xml文gQ但必须要有TOMCAT_HOME/conf/Catalina/localhost的文Ӟq样与最初安装tomcat的webapps文g讄相同Q我个h认ؓQ?/font>


?lt;Host></Host>标签下设|?lt;Context></Context>标签如下Q?br>
<Host name="localhost"  appBase="E:\JavaProject\eclipse33Project\test"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
            
        <Context path="" docBase="WebRoot" debug="0" reloadable="true"></Context>

<Host>

q样只可以设定特定的<Context>标签中虚拟\径。如果E:\JavaProject\eclipse33Project\test目录下还有其它的目录如App2Q如果没有在<Host>标签下设|?lt;Context>标签Q则无法打开其虚拟\径?br>

所有Context的实现支持如下属性:
属?/font> 描述
g表在context及其子容器(包括所有的wrappersQ上调用backgroundProcessҎ的gӞ以秒为单位。如果g时值非负,子容器不会被调用Q也是说子容器使用自己的处理线E。如果该gؓ正,会创Z个新的线E。在{待指定的时间以后,该线E在L及其 子容器上调用backgroundProcessҎ。context利用后台处理sessionq期Q监类的变化用于重新蝲入。如果没有指定,该属性的~省值是Q?Q说明context依赖其所属的Host的后台处理?/td>
实现的Javacd。该cdd?code>接口。如果没有指定,使用标准实现Q在下面定义Q?/td>

如果惛_用cookies来传递session identifierQ需要客L支持cookiesQ,设ؓture。否则ؓfalseQ这U情况下只能依靠URL Rewriting传递session identifier?/p>

 

如果惛_应用内调用ServletContext.getContext()来返回在该虚拟主Zq行的其他web application的request dispatcher,设ؓtrue。在安全性很重要的环境中Q设为falseQ得getContext()Lq回null。缺省gؓfalse?/p>

该web应用的文档基准目录(Document BaseQ也UCؓContext RootQ,或者是WAR文g的\径。可以用绝对\径,也可以用相对于context所属的Host的appBase路径?/p>

 

如果惛_用该Context元素中的讄覆盖DefaultContext中相应的讄Q设为true。缺省情况下使用DefaultContext中的讄?/p>

设ؓtrueQ允许context使用container servletsQ比如manager servlet?/p>

 

web应用的context路径。catalina每个URL的v始和context pathq行比较Q选择合适的web应用处理该请求。特定Host下的context path必须是惟一的。如果context path为空字符Ԍ""Q,q个context是所属Host的缺省web应用,用来处理不能匚wMcontext path的请求?/p>

 

如果希望Catalina监视/WEB-INF/classes/?WEB-INF/lib下面的类是否发生变化Q在发生变化的时候自动重载web applicationQ设为true。这个特征在开发阶D很有用Q但也大大增加了服务器的开销。因此,在发布以后,不推荐用。但是,你可以用Manager应用在必要的时候触发应用的重蝲?/td>

org.apache.catalina.Wrapper实现cȝ名称Q用于该Context理的servlets。如果没有指定,使用标准的缺省倹{?/p>

 



SIMONE 2007-08-11 23:22 发表评论
]]>
վ֩ģ壺 ͨ| | ʦ| ƽ| ƽ| | ɳ| | | | | ˮ| | | | | ݶ| | | ߰| Ȫ| Ͽ| | | | | ԫ| | ǡ| | | | | ÷| | | ˷| ۩| ɽ| Դ| |