Hello there,

Am using JDK 1.5 and Tomcat 5.5.9...

I have two init servlets for the following purposes:

1. One is for logging

2. The other is for loading (and parsing) XML based configuration
files using Commons Digester.

When I go to %CATALINA_HOME%/conf/server.xml and inside the <HOST>
tag, when I set the unpackWars attribute to false, I see a bunch of
null values inside where my logging is supposed to be set!

If I set it to true, everything works well!

e.g. when I set unpackWars = false, redeploy my app, and then start
Tomcat this is what I get:

Dec 21, 2006 1:20:47 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Dec 21, 2006 1:20:47 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 875 ms
Dec 21, 2006 1:20:48 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Dec 21, 2006 1:20:48 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.9
Dec 21, 2006 1:20:48 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Dec 21, 2006 1:20:48 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive mysampleapp.war
log4j.properties not found,
C:\DevTools\tomcat\jakarta-tomcat-5.5.9\bin\nullWEB-INF\log4j.properties
attributes-config.xml not found,
C:\DevTools\tomcat\jakarta-tomcat-5.5.9\bin\nullWEB-INF\attributes-config.xml

My %CATALINA_HOME% is c:\DevTool\tomcat\jakarta-tomcat-5.5.9\

and when I deploy my application, its supposed to auto load these
particular files inside %CATALINA_HOME%\myapp\WEB-INF, but since I
didn't want to unpack my war files, it puts that weird nullWEB-INF
inside the particular path!?

Does this mean that I can't have my servlets load init params unless
my war files is always unpacked?

Here's some code for your review:

<!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd";>

<web-app>

   <display-name>MySampleApp</display-name>
   <description>
       MySampleApp
   </description>

   <servlet>
     <servlet-name>MySampleAppServlet</servlet-name>
     <servlet-class>com.acme.MySampleAppServlet</servlet-class>
   </servlet>

   <servlet-mapping>
     <servlet-name>MySampleAppServlet</servlet-name>
     <url-pattern>/app</url-pattern>
   </servlet-mapping>

        <servlet>
      <servlet-name>log4j-init</servlet-name>
      <servlet-class>com.acme.logging.Log4jInitServlet</servlet-class>
      <init-param>
          <param-name>log4j-init-file</param-name>
          <param-value>WEB-INF\log4j.properties</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
  </servlet>      

  <servlet>
      <servlet-name>xml-config-init</servlet-name>
      <servlet-class>com.acme.config.XmlConfigInitServlet</servlet-class>
      <init-param>
          <param-name>xml-config-file</param-name>
          <param-value>WEB-INF\attributes-config.xml</param-value>
      </init-param>
      <load-on-startup>2</load-on-startup>
  </servlet>

</web-app>

package com.acme.logging;

import java.io.File;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.PropertyConfigurator;

public class Log4jInitServlet extends HttpServlet {
        public void init() throws ServletException {
       String prefix = getServletContext().getRealPath("/");
       String file = getInitParameter("log4j-init-file");
       File propFile = new File(prefix+file);
       if(!propFile.exists()){
           System.out.println("log4j.properties not found, " +
propFile.getAbsolutePath());
       }
       PropertyConfigurator.configureAndWatch(propFile.getAbsolutePath(),10000);
   }
}

package com.acme.config;

import java.io.File;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

import com.acme.AttributeBeanXmlConfigHelper;

public class XmlConfigInitServlet extends HttpServlet {
        
        public void init() throws ServletException {
                String prefix = getServletContext().getRealPath("/");
                String file = getInitParameter("xml-config-file");
                File xmlConfigFile = new File(prefix + file);
                if (!xmlConfigFile.exists()) {
                        System.out.println("attributes-config.xml not found, "
                                        + xmlConfigFile.getAbsolutePath());
                }
                try {

                        // Configure Digester from XML ruleset
                        AttributeBeanXmlConfigHelper.parse(xmlConfigFile);
                
                        Logger.getLogger(this.getClass()).warn("Finished parsing the 
config file.");

                } catch (Exception ex) {
                        ex.printStackTrace();
                }
        }
}

Has anyone experienced the same kind of thing?

Happy holidays,

JD

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to