1 Reply Latest reply on Feb 15, 2007 10:02 AM by casadelnorte

    Log4J and JBoss classloader issue?


      After upgrading (at the same time unfortunately, god how dumb) to MyEclipseIDE 5.1 and JBoss 4.0.5GA, I've been having issues with application logging:

      09:53:59,242 ERROR [STDERR] log4j:ERROR A "org.jboss.logging.util.OnlyOnceErrorHandler" object is not assignable to a "org.apache.log4j.spi.ErrorHandler" variable.
      09:53:59,243 ERROR [STDERR] log4j:ERROR The class "org.apache.log4j.spi.ErrorHandler" was loaded by
      09:53:59,244 ERROR [STDERR] log4j:ERROR [WebappClassLoader
       delegate: false
      ----------> Parent Classloader:
      ] whereas object of type
      09:53:59,245 ERROR [STDERR] log4j:ERROR "org.jboss.logging.util.OnlyOnceErrorHandler" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@7471e0].
      09:53:59,723 ERROR [STDERR] log4j:ERROR Could not create an Appender. Reported error follows.
      09:53:59,724 ERROR [STDERR] java.lang.ClassCastException: org.jboss.logging.appender.DailyRollingFil

      My application .classpath is:
      <?xml version="1.0" encoding="UTF-8"?>
       <classpathentry kind="src" path="src"/>
       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
       <classpathentry kind="con" path="com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER"/>
       <classpathentry kind="lib" path="/Applications/Java/jtds-1.2-dist/jtds-1.2.jar"/>
       <classpathentry kind="lib" path="/Applications/Java/javamail-1.4/mail.jar"/>
       <classpathentry kind="lib" path="/Applications/Java/jaf-1.1/activation.jar"/>
       <classpathentry kind="lib" path="/Applications/Java/quartz-1.5.2/quartz-1.5.2.jar"/>
       <classpathentry kind="lib" path="/Applications/Java/commons-lang-2.1/commons-lang-2.1.jar"/>
       <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
       <classpathentry kind="lib" path="/Applications/Java/logging-log4j-1.2.14/dist/lib/log4j-1.2.14.jar"/>
       <classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>

      JBoss starts fine with no applications deployed. But when I deploy one - even a simple test - using log4j, the error shows up. The application will still run, but without logging.

      There are several posts on the net about this exact issue, with a variety of responses, none of which work for me.

      I have even tried several versions of Log4J, including the one in jboss, with no change in behavior.

      I've been using JBoss and MyEclipseIDS for years, but with after the upgrade I'm having this problem with all of my applications.

      Here's the index.jsp page for the simple test application:
      <%@ page language="java" import="java.util.*" import="org.apache.log4j.Logger" pageEncoding="ISO-8859-1"%>
      String path = request.getContextPath();
      String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
       <base href="<%=basePath%>">
       <title>My JSP 'index.jsp' starting page</title>
       <meta http-equiv="pragma" content="no-cache">
       <meta http-equiv="cache-control" content="no-cache">
       <meta http-equiv="expires" content="0">
       <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
       <meta http-equiv="description" content="This is my page">
       <link rel="stylesheet" type="text/css" href="styles.css">
       Hello!<br />
       System.out.println("hello from the page");
       Logger log = Logger.getLogger(this.getClass().getName());
       log.info("hello from the logger!");

      with it's classpath:
      <?xml version="1.0" encoding="UTF-8"?>
       <classpathentry kind="src" path="src"/>
       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
       <classpathentry kind="con" path="com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER"/>
       <classpathentry kind="lib" path="/Applications/Java/jboss-4.0.5.GA/server/default/lib/log4j.jar"/>
       <classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>

      With the Logger stuff commented out, and without Log4j in the classpath, it works fine. Add Log4J, and you get the errors.

      I've tried everything I can think of.

      MacOSX 10.4.8ppc
      Java 1.5_06
      MyEclipseIDE 5.1.0GA
      Eclipse 3.2.1

      Anyone have any thoughts about how to proceed?

        • 1. Re: Log4J and JBoss classloader issue?

          Interesting update: I deployed my TestLog4J small application with only an index.jsp - as exploded - not packaged, and deleted ../WEB-INF/lib/log4j.jar. That works fine - no errors:

          ./server/default/conf/log4j.xml snippets:

           <!-- ====================== -->
           <!-- Application: TestLog4J -->
           <!-- ====================== -->
           <!-- A size based file rolling appender -->
           <appender name="TESTLOG4J" class="org.jboss.logging.appender.RollingFileAppender">
           <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
           <param name="File" value="${jboss.server.log.dir}/testLog4J.log"/>
           <param name="Append" value="false"/>
           <param name="MaxFileSize" value="500KB"/>
           <param name="MaxBackupIndex" value="1"/>
           <layout class="org.apache.log4j.PatternLayout">
           <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
           <category name="index.jsp">
           <priority value="INFO" />
           <appender-ref ref="TESTLOG4J" />

          Run output:
          08:51:14,210 INFO [STDOUT] hello from the page
          08:51:14,212 INFO [index_jsp] hello from the logger!

          Which implies it's a jar conflict. What's the "proper" way to add Log4J logging to JBoss? If I don't specify Log4J in my build path, the application won't compile. And, we have to deploy in production a package.