I have been using Log4j to development my web application and it has been working perfectly. Yesterday I just put the "jakarta-poi-1.5.1-final- 20020615.jar" file into my WEB-INF/lib directory of my web app, the logger i have been using become silent. I neither changed other configuration nor my code. I have tried removing the file from the lib directory and the log4j starts working again. Here is my configuration: Container: Oracle9iAS (9.0.2.0.0) Containers for J2EE Log4j: version 1.2.3 POI: version 1.5.1 final Thanks. Paul
Look inside the jar, probably there is a property file that confuses log4j configuration; remove it and it should work ok... If it's not there, please report here. Thanks.
I have had the same problem. Indeed, there is a log4j.properties file in the jar. Thus, adding the POI jar to the CLASSPATH *MAY* change program behaviour, even if no POI class is used at all. I'm not sure this is what should be expected. Is there are reason for the log4j.properties file to actually be there? POI currently does not use Commons-Logging or Log4J at all... Here's a test that surprises, if run with or without POI in the classpath: package com.mplify.win2k.diskmon; import org.apache.log4j.Appender; import java.util.Enumeration; import org.apache.log4j.Logger; import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.TTCCLayout; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.LogManager; /********************************************************************** * Simple test of Log4J. * By default, the program just writes out a description of the logging * hierarchy to stdout using the System.out PrintStream. If the first * argument to the program is 'WITH', a logger is allocated before the * logging hierarchy is printed to stdout. * * With 'jakarta-poi' in the classpath: * ==================================== * * WITH Logger allocated * LOGGER: root * Level = DEBUG <-- our level for root (POI sets it to FATAL) * Additivity = true * Appender name = stdout <-- Jakarta-POI debugging appender * Appender name = null <-- our appender for root * LOGGER: com.mplify.win2k.diskmon.Log4JTest.main <-- our method-specific logger * Level = null * Additivity = true * LOGGER: org <-- Jakarta-POI specific logger * Level = FATAL <-- ...it works at level FATAL * Additivity = true * Appender name = stdout <-- Jakarta-POI debugging appender * * WITHOUT Logger allocated * LOGGER: root * Level = DEBUG <-- our level for root (POI sets it to FATAL) * Additivity = true * Appender name = stdout <-- Jakarta-POI debugging appender * Appender name = null <-- our appender for root * LOGGER: org <-- Jakarta-POI specific logger * Level = FATAL <-- ...it works at level FATAL * Additivity = true * Appender name = stdout <-- Jakarta-POI debugging appender * * With no 'jakarta-poi' in the classpath: * ======================================= * * WITH Logger allocated * LOGGER: root * Level = DEBUG <-- our level for root * Additivity = true * Appender name = null <-- our appender for root * LOGGER: com.mplify.win2k.diskmon.Log4JTest.main <-- our method-specific logger * Level = null * Additivity = true * * 20 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 0 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 1 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 2 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 3 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 4 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 5 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 6 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 7 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 8 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 9 * * WITHOUT Logger allocated * LOGGER: root * Level = DEBUG <-- our level for root * Additivity = true * Appender name = null <-- our appender for root *********************************************************************/ public class Log4JTest { private final static String PACKAGE = "com.mplify.win2k.diskmon"; private final static String CLASS = PACKAGE + ".Log4JTest"; /** * List the whole setup of Log4J's default Hierarchy * Except the Renderers which are not listable */ public static void listSetupOfDefaultLog4JHierarchy() { StringBuffer buf = new StringBuffer(); // // first the root element of the default hierarchy // { Logger root = Logger.getRootLogger(); buf.append("LOGGER: "); buf.append(root.getName()); buf.append("\n"); buf.append(" Level = "); buf.append(root.getLevel()); buf.append("\n"); buf.append(" Additivity = "); buf.append(root.getAdditivity()); buf.append("\n"); Enumeration appEnum = root.getAllAppenders(); while (appEnum.hasMoreElements()) { Appender app = (Appender) (appEnum.nextElement()); buf.append(" Appender name = "); buf.append(app.getName()); buf.append("\n"); // may want to check the filter and the layout of the appender } } // // then for the rest of the categories // { Enumeration enum = LogManager.getCurrentLoggers(); while (enum.hasMoreElements()) { Logger cat = (Logger) (enum.nextElement()); buf.append("LOGGER: "); buf.append(cat.getName()); buf.append("\n"); buf.append(" Level = "); buf.append(cat.getLevel()); buf.append("\n"); buf.append(" Additivity = "); buf.append(cat.getAdditivity()); buf.append("\n"); Enumeration appEnum = cat.getAllAppenders(); while (appEnum.hasMoreElements()) { Appender app = (Appender) (appEnum.nextElement()); buf.append(" Appender name = "); buf.append(app.getName()); buf.append("\n"); // may want to check the filter and the layout of the appender } } } System.out.println(buf.toString()); } /** * Example main() code * 2) The TTCCLayout timing info is crap --- Is this also the case in UNIX? */ public static void main(String[] argv) { Logger logger = null; if (argv != null && argv.length >= 1 && "WITH".equalsIgnoreCase(argv [0])) { logger = Logger.getLogger(CLASS + ".main"); System.out.println("WITH Logger allocated"); } else { System.out.println("WITHOUT Logger allocated"); } // // prepare logging // Layout layout = new TTCCLayout(); Logger.getRoot().addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT)); Logger.getRoot().setLevel(Level.DEBUG); // // write out how the hierarchy looks now // listSetupOfDefaultLog4JHierarchy(); // // then write some stuff // if (logger != null) { for (int i = 0; i < 10; i++) { logger.debug("This is message " + i); } } } }
This seems to have been fixed in the dev releases. They no longer contain a log4j.properties in the poi-xxx.jar. so can i mark this as fixed. I doubt we will do a release on the 1.5 branch just for this. Will add a FAQ for this.
This is the code: Below is the error message.What seems to be the problem?Do i have to know Logger of Log4J to use HSSF? import java.io.*; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class FirstExcelTest { public static void main(String[] args) { HSSFWorkbook wb = new HSSFWorkbook(); FileOutputStream fileOut=null; try { fileOut = new FileOutputStream("c:\\workbook.xls"); wb.write(fileOut); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } java.lang.NoClassDefFoundError: org/apache/log4j/Logger at org.apache.poi.hssf.usermodel.HSSFWorkbook.<clinit> (HSSFWorkbook.java:115) at com.qinteraction.Excel.AnotherExcel.main(AnotherExcel.java:24) Exception in thread "main"