﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-VIRGIN FOREST OF JAVA-文章分类-TOMCAT / RESIN</title><link>http://www.blogjava.net/RR00/category/15207.html</link><description>不要埋头苦干，要学习，学习，再学习。。。。。
&lt;br&gt;
powered  by &lt;font color='orange'&gt;R.Zeus&lt;/font&gt;</description><language>zh-cn</language><lastBuildDate>Sat, 24 May 2008 17:16:00 GMT</lastBuildDate><pubDate>Sat, 24 May 2008 17:16:00 GMT</pubDate><ttl>60</ttl><item><title>birt tomcat  Cannot load JDBC Driver class</title><link>http://www.blogjava.net/RR00/articles/202435.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Fri, 23 May 2008 08:24:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/202435.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/202435.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/202435.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/202435.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/202435.html</trackback:ping><description><![CDATA[Cannot load JDBC Driver class: com.mysql.jdbc.Driver <br />
<br />
fuck !! because of&nbsp; deleting the <span style="color: red;">temp </span>dir in tomcat,it report this error! foolish birt! why can't it create a temp dir for the db driver to store!!<br />
<img src ="http://www.blogjava.net/RR00/aggbug/202435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2008-05-23 16:24 <a href="http://www.blogjava.net/RR00/articles/202435.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>&lt;Context ../&gt;</title><link>http://www.blogjava.net/RR00/articles/162447.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Thu, 22 Nov 2007 11:07:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/162447.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/162447.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/162447.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/162447.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/162447.html</trackback:ping><description><![CDATA[&lt;Context path="/test" docBase="D:/WebRoot/Tomcat/testa"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; debug="0" privileged="true"/&gt;<br />
<img src ="http://www.blogjava.net/RR00/aggbug/162447.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2007-11-22 19:07 <a href="http://www.blogjava.net/RR00/articles/162447.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>装了n次tomcat后tomcat不能启动</title><link>http://www.blogjava.net/RR00/articles/92681.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Tue, 09 Jan 2007 09:56:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/92681.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/92681.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/92681.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/92681.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/92681.html</trackback:ping><description><![CDATA[几乎每次建新项目都会用新的tomcat，结果今天起不来了，错误报告找不到路径，察看了环境变量，发现有个class_path属性指向一个删除的目录中的jar，把它删后tomcat 就正常了。在找不到问题的情况下，重装系统也是一个不多的选择，ghost也快。<img src ="http://www.blogjava.net/RR00/aggbug/92681.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2007-01-09 17:56 <a href="http://www.blogjava.net/RR00/articles/92681.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Resin search</title><link>http://www.blogjava.net/RR00/articles/79447.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Mon, 06 Nov 2006 09:43:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/79447.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/79447.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/79447.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/79447.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/79447.html</trackback:ping><description><![CDATA[  according to project's need,I download the resin and expore this open-source server the first time for me.below is some problem and may be with solved ways.<br />1.cache for IE.I don't konw intellij IDE make this trick or the resin.no matter I change the jsp or delete it,the page seem never change.after I change the struts-comfig.xml or the tiles.xml pointing to another jsp coping from the sick page,then I can do what I want and not restart the server.<br />2.the resin will create a dir named 'work' in the 'web-inf'.and when compile,the java file in the <br />'work' dir may be reported error.so I delete it.<br />3.Hibernate error.for associate relation,Tomcat doesn't check but Resign check strictly.this may be becaust of the jsp-compile way.<br />4.For intellij-IDE's  resin plug,it didn't compile before run just as Tomcat plug.so you must compile yourself if any class changed.<br />5.the most different between Tomcat and Resin is the JSTL compile.Resin will generate the fast-jstl code and Tomcat do nothing.Resin contains the jstl-11.jar.In my former  training demo,the company jar we used seems associate with the jstl-xx.jar,so I can't delete the jstl jar<br />from the demo lib.Then the demo run error when in Resin until close the fast-jstl.<br /><br /><font color="#ff1493">resin.conf<br /> &lt;web-app-default&gt;<br />...<br />  &lt;jsp fast-jstl='false'/&gt;<br />....<br /> &lt;/web-app-default&gt;</font><br /><br />it also can set for a appointed web-app.<br /><br />version:<br />intellij IDE: 6.0.1<br />Resin:resin-pro-3.0.21<br />DB: sql-server<br /><img src ="http://www.blogjava.net/RR00/aggbug/79447.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2006-11-06 17:43 <a href="http://www.blogjava.net/RR00/articles/79447.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>more server run applicatin on the same database will be error!</title><link>http://www.blogjava.net/RR00/articles/76370.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Fri, 20 Oct 2006 05:35:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/76370.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/76370.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/76370.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/76370.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/76370.html</trackback:ping><description><![CDATA[
		<p align="left">                      <font color="#000000" size="5">if there are more than two server run with the same system code<br />            and call the <font color="#ff1493">save</font> method at the same time ,it will be result of hibernate<br />            error!because hibernate get the max id for ganerator and store it in<br />            cache for next time using.so one server will get the expired id if another<br />            server change the database following.<br />            befroe save object,hibernate will excute this sql after the server start up <font color="#ff1493">once</font>:<br />             Hibernate: select max(ID) from TB_LOG<br />            TB_LOG is my log table.</font></p>
<img src ="http://www.blogjava.net/RR00/aggbug/76370.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2006-10-20 13:35 <a href="http://www.blogjava.net/RR00/articles/76370.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Set the Logging Level Over a Tomcat Cluster Dynamically</title><link>http://www.blogjava.net/RR00/articles/69693.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Thu, 14 Sep 2006 09:03:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/69693.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/69693.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/69693.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/69693.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/69693.html</trackback:ping><description><![CDATA[
		<table cellspacing="0" cellpadding="0" border="0">
				<tbody>
						<tr>
								<td align="left" width="75">
										<img height="75" src="http://assets.devx.com/articleicons/6484.gif" width="75" align="left" border="0" />
								</td>
								<td width="10"> </td>
								<td valign="top">
										<div class="articleTitle">Set the Logging Level Over a Tomcat Cluster Dynamically</div>
										<div class="articleDek">Rather than modifying your Log4J configuration and then redeploying the correct code version with the modified logging level, you can dynamically set the Log4J logging level over each node in a Tomcat cluster with JMX. </div>
										<br />
										<table cellspacing="0" cellpadding="0" width="100%" border="0">
												<tbody>
														<tr>
																<td class="articleAuthor" align="left">by Jon Dickinson</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />henever you have to fix a problem in a production environment, one of the most common issues is retrieving some useful debug information to tell you what happened. Of course, to avoid needless notifications and enormous log files, most production systems are configured to log only errors. To avoid having to modify your Log4J configuration and then redeploy the correct version of the code with the modified logging level, why not just implement a mechanism for dynamically changing the logging level? <br /><a href="http://www.devx.com/Java/Article/32359#codeitemarea"></a><div><br />Log4J registers a number of MBeans, one of which provides access to the root logger. You can dynamically modify the logging level of the root logger by implementing the following servlet to set the appropriate MBean property through JMX: <pre><code>
public class SetLog4jLevelServlet extends HttpServlet {
    private static final Log log = LogFactory.getLog(SetLog4jLevelServlet.class);

    protected void doGet(HttpServletRequest request, 
            HttpServletResponse response) 
            throws ServletException, IOException {
        List list = MBeanServerFactory.findMBeanServer(null);
        MBeanServer server  = (MBeanServer)list.iterator().next();

        try {
            String loggingLevel = request.getParameter("level");
            Attribute attribute = new Attribute("priority", loggingLevel);
            ObjectName objectName = new ObjectName("log4j:logger=root");
            server.setAttribute(objectName, attribute);
        } catch (Exception e) {
            log.error("log4j:logger=root", e);
        }
    }
}
</code></pre><p>The first two lines of the doGet method look up the MBeanServer. Log4J registers the root logger with the name <i>log4j:logger=root</i>. This MBean provides a property to set the logging level of the root logger. You set the priority of the root logger by passing the ObjectName of the MBean to operate on, along with an instance of javax.management.Attribute to the MBean Server. In this case, you want to set the "priority" attribute. The value will be the new logging level you have specified<br /><br /></p><h4>A Log4J MBean for Each Log4J Configuration</h4><p>Although this technique seems simple, if your Tomcat cluster hosts a number of Web applications—each with its own Log4J configuration that allows it to log to a separate log file—then you will run into your first problem. Given multiple Log4J configurations, only the first one loaded by the JVM will have a root logger MBean associated with it. The reason for this is Log4J hard-codes the JMX Domain that it uses when registering its MBeans as <i>log4j</i>, and the JMX server doesn't allow duplicate names.<br /><br /></p><div><p>The way round this is to leave a Tomcat server Log4J configuration (jars under server/lib and property files under server/classes) registered under the default Log4J name <i>log4j:logger=root</i>. Then register the root logger for each Web application in a startup servlet, using the Web application name to identify the domain: </p><pre><code>
public class RegisterLog4JMBeanServlet extends HttpServlet {

    private static final Log log = LogFactory.getLog(RegisterLog4JMBeanServlet.class);

    public void init(ServletConfig servletConfig) 
            throws ServletException {
        ServletContext context = servletConfig.getServletContext();
        String webappName = context.getServletContextName();
        Hashtable&lt;String, String&gt; nameParameters = new Hashtable&lt;String, String&gt;();
        nameParameters.put("logger", "root");

        Logger rootLogger = LogManager.getRootLogger();
        LoggerDynamicMBean mbean = new LoggerDynamicMBean(rootLogger);
        List list = MBeanServerFactory.findMBeanServer(null);
        MBeanServer server  = (MBeanServer)list.iterator().next();

        ObjectName objectName = null;
        try {
            objectName = new ObjectName(webappName, nameParameters);
            server.registerMBean(mbean, objectName);
        } catch (Exception e) {
            log.error("Problems registering Log4J MBean", e);
        }
    }
}
</code></pre><p>You will end up with an MBean named &lt;<i>web-app-name&gt;: logger=root</i> for each Web application. The webappName is retrieved from the &lt;<i>display-name</i>&gt; element in your application's web.xml file, and the application's root logger is retrieved by calling <code>LogManager.getRootLogger()</code>. Then you can use the LoggerDynamicMBean class from Log4J to create your MBean from the root logger definition. 
</p><p>To create a distinct ObjectName for the new MBean, you should use the Web application name as the JMX domain (this is the text before the colon) and then register the Root Logger MBean with the new ObjectName. This will guard against conflicts with other Log4J MBeans. 
</p><p>Now that you have registered your Root Logger under a different domain, you must modify the servlet that sets the logging level. So in SetLog4JlevelServlet, change this: </p><pre><code>
ObjectName objectName = new ObjectName("log4j:logger=root");
</code></pre><p>To this: </p><pre><code>
ServletContext context = servletConfig.getServletContext();
String webappName = context.getServletContextName();
Hashtable&lt;String, String&gt; nameParameters = new Hashtable&lt;String, String&gt;();
nameParameters.put("logger", "root");
ObjectName objectName = new ObjectName(webappName, nameParameters);
</code></pre><p>When setting up your Log4J configuration, give your Log4J appenders unique names. Otherwise, they will not get registered to the JMX server and you will get lots of the following errors in your log files at startup: </p><pre><code>
ERROR main org.apache.log4j.jmx.LoggerDynamicMBean ? - Could not add appenderMBean for [&lt;<i>appender_name</i>&gt;].
javax.management.InstanceAlreadyExistsException: log4j:appender=&lt;<i>appender_name</i>&gt;
</code></pre><p>Again, the reason for this is because the JMX domain name his hard-coded to <i>log4j</i>, so if you have repeated appender names then only the first of these will be registered. 
</p><p>At this point, configuring the MX4J HTTP adaptor in your Tomcat server might be useful. This will give you a visual representation of the MBeans you are creating and manipulating, and show you what else is exposed via MBeans within Tomcat. To do this, you must put the mx4j-tools.jar file (download it at <a href="http://mx4j.sourceforge.net/" target="new"><font color="#002c99">mx4j.sourceforge.net</font></a>) in your common/lib directory. Then configure your server.xml file to set up the connector as follows: </p><pre><code>
    &lt;Connector port="8010" 
           handler.list="mx" 
           mx.enabled="true" 
           mx.httpHost="localhost"
           mx.httpPort="8013"
           protocol="AJP/1.3"/&gt;
</code></pre><p>When you start your server, you will be able to access the MX4J HTTP connector through your browser at http://localhost:8013, assuming you have no other Tomcat connector running on port 8010. 
</p><h4>Set the Logging Level for All the Nodes in Your Cluster</h4><p>Once you have made the previously discussed changes, you will be able to set the Log4J logging level dynamically for any application running in Tomcat. The next challenge is to make sure you can set the logging level for every node in the cluster. You could either call this servlet manually on each node in the cluster or get the servlet to send a message to every other node in the cluster so the logging levels are always the same across the cluster</p><div>To send a message to the other nodes in a Tomcat cluster, you need to call the <code>send(ClusterMessage)</code> method on the org.apache.catalina.cluster.SimpleTcpCluster class. When implementing a ClusterMessage, you must populate the details of the cluster node that was responsible for sending the request. (<a href="javascript:showSupportItem('listing1')"><font color="#002c99">Listing 1</font></a> provides an example that retrieves the information through the Tomcat MBeans.) The first step is to provide an implementation of the ClusterMessage interface to pass the new logging level and to determine for which application you want to set the logging level. 
<p>It may seem strange, but you must use JMX over RMI to send the message to the cluster because the interface implemented in <a href="javascript:showSupportItem('listing1')"><font color="#002c99">Listing 1</font></a> is defined within the Tomcat server class loader (i.e., it exists in a jar file in the server directory). You will instantiate that class in a Web application, which uses a totally separate class loader (it exists in the WEB-INF directory of your Web application). This means that the cluster message you instantiate in your Web application and send to the SimpleTcpCluster class will be different from the cluster message definition that is placed in the Tomcat server class loader. If you try to send your message directly through JMX, your cluster message instance will not match the cluster message definition accessible to the SimpleTcpCluster class and the call will fail. (See the <a href="http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html" target="new"><font color="#002c99">Tomcat documentation on class loaders</font></a> for a definition of how the class loaders are configured for the Tomcat server.) 
</p><p>The workaround is to use JMX over RMI so the cluster message is serialized in the Web application class loader, instantiated in the Tomcat server class loader (and that is the important point), and then de-serialized. The following method opens a connection to the local JVM's JMX server over RMI, looks up the MBean that wraps the SimpleTcpCluster, and then invokes the <code>send(ClusterMessage)</code> operation on the MBean: </p><pre><code>
public static void sendLogMessageEvent(String applicationName, String logLevel) {
    String port = System.getProperty("com.sun.management.jmxremote.port");
    String urlForJMX = JMX_SERVICE_PREFIX + HOST + ":" + port + JMX_SERVICE_SUFFIX;

    try {
        JMXServiceURL url = new JMXServiceURL(urlForJMX);
        JMXConnector connector = JMXConnectorFactory.connect(url, null);
        MBeanServerConnection server = connector.getMBeanServerConnection();
        ObjectName cluster = new ObjectName("Catalina:type=Cluster,host=localhost");
        log.debug("Cluster cluster: " + cluster.toString());

        LogLevelMessage message = new LogLevelMessage();
        message.setLoggingLevel(logLevel);
        message.setApplication(applicationName);

        Object[] params = new Object[] {message};
        String[] types = new String[] {"org.apache.catalina.cluster.ClusterMessage"};
        server.invoke(cluster, "send", params, types);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
</code></pre><p>You should call this method in your SetLog4JLevelServlet to ensure that a message is sent to the other members of the cluster when you set the logging level. 
</p><p>You will need to configure your Tomcat server to allow a JMX connection to be opened up over RMI. Simply add the following line to your catalina.bat file in the bin directory: </p><pre><code>
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=8012 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false
</code></pre><p>For a quick guide on applying security to this configuration, see the <a href="http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html" target="new"><font color="#002c99">Tomcat documentation</font></a>. For a more in-depth look at configuring JMX Remote, see the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html#remote" target="new"><font color="#002c99">Sun documentation</font></a>. 
</p><div><h4>Receiving the Message in the Other Nodes</h4>Once you are able to send these messages to the other nodes in the cluster, you will need to implement a Tomcat ClusterListener to receive the events. This implementation will set the logging level for the correct MBean determined by the application name that is passed as part of the message: <pre><code>
public class ClusterLoggingListener extends ClusterListener {

    private static final Log log = LogFactory.getLog(ClusterLoggingListener.class);
    
    public void messageReceived(ClusterMessage message) {
        if(message instanceof LogLevelMessage) {
            LogLevelMessage logMessage = (LogLevelMessage) message;
            List list = MBeanServerFactory.findMBeanServer(null);
            MBeanServer server  = (MBeanServer)list.iterator().next();
            Hashtable&lt;String, String&gt; nameParameters = new Hashtable&lt;String, String&gt;();
            nameParameters.put("logger", "root");
            try {
                ObjectName logBean = new ObjectName(logMessage.getApplication(), nameParameters);
                Attribute attribute = new Attribute("priority", logMessage.getLoggingLevel());
                server.setAttribute(logBean, attribute);
            } catch (Exception e) {
                log.error("Problem setting the logging level for application " + 
                        logMessage.getApplication() + " to level " + 
                        logMessage.getLoggingLevel(),e);
            }
        }
    }
    public boolean accept(ClusterMessage message) {
        return message instanceof LogLevelMessage;
    }
}
<div><pre></pre><p>You must deploy this class in the server directory and enter it in the Tomcat server.xml file as a ClusterListener within the <code>&lt;Cluster&gt;</code> element: </p><pre><code>
&lt;ClusterListener className="dynamiclogging.tomcat.ClusterLoggingListener"/&gt;
</code></pre><p>You should now be able to set the logging level for any application, over all nodes, in the cluster by calling SetLog4JLevelServlet on any node in the cluster. </p><p></p><h4>Deploying the Example Code</h4>To deploy <a href="http://assets.devx.com/sourcecode/16944.zip"><font color="#002c99">the example code</font></a> for setting the logging level in your cluster, take the following steps: <ol><li>Load the Eclipse project and build it using the dist target. This will create set-log-levels.war and set-log-levels-server.jar in the dist directory. </li><li>Put the set-log-levels-server.jar in the Tomcat server\lib directory and deploy the set-log-levels.war file across the cluster. </li><li>Use the SetLog4jLevelServlet (e.g., <code>/setLogLevel?level=debug</code>) to set the logging level and use PerformLogTestServlet (<code>/testLogLevel</code>) to test the logging level changes. </li></ol><p></p></div></code></pre></div></div></div></div><img src ="http://www.blogjava.net/RR00/aggbug/69693.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2006-09-14 17:03 <a href="http://www.blogjava.net/RR00/articles/69693.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>log4j in tomcat</title><link>http://www.blogjava.net/RR00/articles/69638.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Thu, 14 Sep 2006 06:41:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/69638.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/69638.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/69638.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/69638.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/69638.html</trackback:ping><description><![CDATA[
		<p>log4j.xml 可以放在2个地方：<br />1〉使用<strong>springframework</strong>在web.xml中配置<br /><font color="#000000">//设置<font color="#ff1493">webAppRootKey</font>的别名，<br />//如果不设置，在log4j.xml中设置为&lt;param name="File" value="<font color="#0000ff">${webapp.root}/</font>WEB-INF/log/frame.log " /&gt;<br />//否则，可以设置为&lt;param name="File" value="<font color="#0000ff">${demo.root}/</font>WEB-INF/log/frame.log " /&gt;<br />//如果不使用<font color="#0000ff">${webapp.root</font>}，就会指向${TOMCAT_HOM},也就是tomcat的安装目录<font color="#ff0000">。</font><br /></font><font color="#a52a2a"> &lt;context-param&gt;<br />  &lt;param-name&gt;<font color="#0000ff">webAppRootKey</font>&lt;/param-name&gt;<br />  &lt;param-value&gt;<font color="#0000ff">demo.root</font>&lt;/param-value&gt;<br /> &lt;/context-param&gt;</font></p>
		<p>
				<font color="#a52a2a">
						<font color="#000000">//设置配置文件</font>   <br />&lt;context-param&gt;<br />        &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;<br />        &lt;param-value&gt;/WEB-INF/log4j.xml&lt;/param-value&gt;<br />    &lt;/context-param&gt;<br /><br /><font color="#000000">//设置监听器<br /></font>  &lt;listener&gt;<br />  &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;<br /> &lt;/listener&gt;<br /></font>这样log4j.xml 就可以WEB-INF里面的任何路径。<br /><br /><strong>Source:<br /></strong><br /><strong>initLogging-&gt;<br />{<br />      WebUtils.setWebAppRootSystemProperty(servletContext);<br /></strong>      {<br />      <strong>String root = servletContext.getRealPath("/");<br />      String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);<br />       String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);<br />        System.setProperty(key, root);<br />    <font color="#ff0000">  //use system property to deal with </font></strong><font color="#ff0000"><font color="#0000ff">${webapp.root}</font> or its alias.<br />      //once I writed careless <font color="#0000ff">${webapp.root}</font> to <font color="#0000ff">{webapp.root}</font> ,and look up the error for much time.<br /></font><strong>          }<br />      String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);<br />      Log4jConfigurer.initLogging(location);<br />      {<br /><br />      <font color="#ff0000">   //distinguish the log4j.xml and log4j.properties</font><br />       <font color="#a52a2a">  if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {<br />            DOMConfigurator.configure(url);<br />        }<br />     else {<br />         PropertyConfigurator.configure(url);<br />     }<br />      }<br /></font>}<br />use <font color="#ff0000">DOMConfigurator.configure("log4j.xml"); </font><font color="#000000">to init config ,then LogFactory can work. the "log4j.xml "<br />may be any name .<font color="#ff0000">DOMConfigurator </font>may use cache mechanism as in LogFactory class .cache machanism is<br />another way to implement "single" design pattern.<br /></font></strong><font color="#008000">------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br /></font>2〉WEB-INF/classes下面 <br /><br />采取这种方式，它的文件appender的相对路径总是指向${TOMCAT_HOM},也就是tomcat的安装目录<font color="#ff0000">。&lt;param name="File" value="demo.log" /&gt; <font color="#000000">会把</font></font><font color="#ff0000">demo.log <font color="#000000">保存到</font></font><font color="#ff0000">${TOMCAT_HOM}/demo.log</font><font color="#ff0000"> ，<br /></font>采用绝对路径则可以任意设置。<br /><br />为了使用相对路径，我们把project放到${TOMCAT_HOMe}/webapps下deploy。<br />如project名为demo，log要保存在demo/log/demo.log文件里，则可以设为：<br /><font color="#ff0000">&lt;param name="File" value="webapps\\demo\\log\\framefile.log" /&gt;<br /><br />---------------------------------------------------------------------------------------------------------------------------<br />---------------------------------------------------------------------------------------------------------------------------<br />---------------------------------------------------------------------------------------------------------------------------<br /></font><font color="#000000">注意<font color="#a52a2a">“\"</font> 要用转义字符<font color="#a52a2a">"\\",</font>如果没加,tomcat启动屏中的路径会变为乱码.<br /><br />tomcat中似乎采取了某种安全策略</font><font color="#000000">,&lt;param name="Append" value="false" /&gt;不起作用。<br /><br />服务器重起后就会新建一个log文件.<br /></font></p>
<img src ="http://www.blogjava.net/RR00/aggbug/69638.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2006-09-14 14:41 <a href="http://www.blogjava.net/RR00/articles/69638.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>