Problem with log4j.xml

Discussions

General J2EE: Problem with log4j.xml

  1. Problem with log4j.xml (4 messages)

    Hello,
    I'm using log4j in a struts application on Weblogic 7.
    I've configured and placed my log4j.xml file in the classpath of my webapp (WEB-INF\classes).
    But it seems it can't be found because:
     - the logs doesn't work properly
     - when I deploy/start my webapp, I get this error msg:
    log4j:ERROR Could not open [log4j.xml].
    java.io.FileNotFoundException: log4j.xml: Le fichier spÚcifiÚ est introuvable
            at COM.jrockit.io.FileNativeIO.open0(Ljava.lang.String;I)I(Native Method)
            at COM.jrockit.io.FileNativeIO.open(Ljava.lang.String;I)Ljava.io.FileDescriptor;(Unknown Source)
            at java.io.FileInputStream.<init>(Ljava.lang.String;)V(Unknown Source)
            at org.apache.log4j.xml.DOMConfigurator.doConfigure(Ljava.lang.String;Lorg.apache.log4j.spi.LoggerRepository;)V(
    DOMConfigurator.java:583)
            at org.apache.log4j.xml.DOMConfigurator.configure(Ljava.lang.String;)V(DOMConfigurator.java:694)
            at com.it.bdc.utils.Log4JPlugin.init(Lorg.apache.struts.action.ActionServlet;Lorg.apache.struts.config.ModuleCon
    fig;)V(Log4JPlugin.java:19)
            at org.apache.struts.action.ActionServlet.initModulePlugIns(Lorg.apache.struts.config.ModuleConfig;)V(ActionServ
    let.java:1158)
            at org.apache.struts.action.ActionServlet.init()V(ActionServlet.java:473)
            at javax.servlet.GenericServlet.init(Ljavax.servlet.ServletConfig;)V(GenericServlet.java:258)
            at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run()Ljava.lang.Object;(ServletStubImpl.java:1111
    )
            at weblogic.security.service.SecurityServiceManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;L
    weblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction;)Ljava.lang.Object;(SecurityServiceM
    anager.java:685)
            at weblogic.servlet.internal.ServletStubImpl.createServlet()Ljavax.servlet.Servlet;(ServletStubImpl.java:935)
            at weblogic.servlet.internal.ServletStubImpl.createInstances()V(ServletStubImpl.java:869)
            at weblogic.servlet.internal.ServletStubImpl.prepareServlet(Lweblogic.servlet.internal.RequestCallback;)V(Servle
    tStubImpl.java:809)
            at weblogic.servlet.internal.WebAppServletContext.preloadServlet(Ljava.lang.String;)V(WebAppServletContext.java:
    2874)
            at weblogic.servlet.internal.WebAppServletContext.preloadServlets()V(WebAppServletContext.java:2819)
            at weblogic.servlet.internal.WebAppServletContext.preloadResources()V(WebAppServletContext.java:2792)
            at weblogic.servlet.internal.WebAppServletContext.setStarted(Z)V(WebAppServletContext.java:4908)
            at weblogic.servlet.internal.WebAppModule.start()V(WebAppModule.java:563)
            at weblogic.j2ee.J2EEApplicationContainer.start([Lweblogic.j2ee.J2EEApplicationContainer$Component;)V(J2EEApplic
    ationContainer.java:1104)
            at weblogic.j2ee.J2EEApplicationContainer.activate(Ljava.lang.String;[Lweblogic.management.configuration.Compone
    ntMBean;)V(J2EEApplicationContainer.java:1140)
            at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(Lweblogic.management.deploy.OamVersion;Lweb
    logic.management.runtime.DeploymentTaskRuntimeMBean;Z)V(SlaveDeployer.java:1164)
            at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(Ljava.util.ArrayList;Z)V(SlaveDeployer.java:784)

            at weblogic.drs.internal.SlaveCallbackHandler$1.execute(Lweblogic.kernel.ExecuteThread;)V(SlaveCallbackHandler.j
    ava:24)
            at weblogic.kernel.ExecuteThread.execute(Lweblogic.kernel.ExecuteRequest;)V(ExecuteThread.java:251)
            at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:219)
            at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread;)V(Unknown Source)


    Does anyone could help me to solve this problem?

    Threaded Messages (4)

  2. Problem with log4j.xml[ Go to top ]

    Yes I too have a same problem with weblogic8.1.
    When I pass log4j.xml to propertyconfigurator, it does nothing.

    But log4j.properties file works fine.

    -Jignesh
  3. Problem with log4j.xml[ Go to top ]

    That's exactly what happened for me too, even using DOMConfigurator rather than PropertyConfigurator (I've red that we have to use DOMConfigurator with log4j.xml).
  4. Solution[ Go to top ]

    After more than 2 days searching the web, I've found the way to solve this problem:
    I get the log4j.xml file like this in the log4j init class:
    DOMConfigurator.configure(Thread.currentThread().getContextClassLoader().getResource("log4j.xml"));
  5. Solution[ Go to top ]

    This is true for getting all the files which are in the WEB-INF/classes folder when you use the weblogic workshop. The reason for this is that we write the java code in a Java project in the weblogic workshop which does not have a container. This java project is internally used either by a web project, web service project, etc which have containers. So to get the files, we use the Thread.currentThread().getContextClassLoader().getResource("log4j.xml")
    which gets the file from the current container from where the java code was called (eg. from the WEB-INF/classes of the web project or web service project)

    It might be a good thing to just have one file in the WEB-INF classes which has the path location of another file XYZ at some constant location and we use the file XYZ for all our constants.

    Prashant.