Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Logging Problem with unpackWARs= "false "

Logging Problem with unpackWARs= "false "

2006-12-21       - By James Dekker

 Back
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 Source code of org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080 (See http://ttp-8080.ora-code.com)
Dec 21, 2006 1:20:47 PM org.apache.catalina.startup.Catalina Source code of org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 875 ms
Dec 21, 2006 1:20:48 PM org.apache.catalina.core.StandardService Source code of org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Dec 21, 2006 1:20:48 PM org.apache.catalina.core.StandardEngine Source code of 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 Source code of org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Dec 21, 2006 1:20:48 PM org.apache.catalina.startup.HostConfig Source code of org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive mysampleapp.war
log4j.properties not found,
C:\DevTools\tomcat\jakarta-tomcat-5 (See http://cat-5.ora-code.com).5.9\bin\nullWEB-INF\log4j.properties
attributes-config.xml not found,
C:\DevTools\tomcat\jakarta-tomcat-5 (See http://cat-5.ora-code.com).5.9\bin\nullWEB-INF\attributes-config.xml

My %CATALINA_HOME% is c:\DevTool\tomcat\jakarta-tomcat-5 (See http://cat-5.ora-code.com).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 Source code of java.io.File;

import javax.servlet.ServletException Source code of javax.servlet.ServletException;
import javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet;

import org.apache.log4j.PropertyConfigurator Source code of 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 Source code of java.io.File;

import javax.servlet.ServletException Source code of javax.servlet.ServletException;
import javax.servlet.http.HttpServlet Source code of javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger Source code of 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@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.