location for log4j.xml

Posted on 2006-05-16
Last Modified: 2012-05-05
I am getting filenotfoundexception: log4j.xml. where do i put the log4j.xml I don't want to put it in the classpath. is there any other way. Also currently I have to put DOMConfigurator.configure("log4j.xml"); inside each method. is there a central place that I can put it in and the application will be able to access it there after.

this is how i am using log4j.xml

import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;

public class CustomerFormAction extends LookupDispatchAction{
  static Logger myLogger = Logger.getLogger(CustomerFormAction.class.getName());

public ActionForward search(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
      throws Exception {

Question by:muthiahmerchant
    1 Comment
    LVL 11

    Accepted Solution

    better is to use the InitServlet which initialises the log4j at the application start. Then u need not to call it anywhere else.

    The location of the log4j.xml is not required to be in classpath, but then u have to keep the location configured in the application. The log4j initializer will then take the location path from the configuration and initialise it.

    InitServlet is just a servlet which will have load-on-startup at application start (so we keep it to 0)

        <!-- Load this servlet at server startup time -->


    call  DOMConfigurator.configure("complete/path/to/log4j.xml"); in initservlet.

    public class InitServlet extends HttpServlet

         * Main method which call all the init steps
         * @throws ServletException
        public void init() throws ServletException

    } // end of InitServlet

    Do the error handling in the above code.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now