title: How can I provide a custom log4j.xml for different ant tasks?
body: <p>I have a build file that as part of the build process relies on several taskdefs.  These taskdef items (for example, webdoclet and jasper2) use log4j as a logger.  Ideally, I'd like to be able to provide a different log4j configuration file for each, but minimally, I'd like to be able to specify which log4j configuration file is used.</p>
  
  <p>What I did that used to work was to put at the front of the classpath the directory containing the log4j.xml that I wanted the taskdef to use.  For example:</p>
  
  <pre>
  &lt;target name="define.jasper2">
    &lt;path id="jspc.classpath">
        &lt;!-- Put this FIRST so Jasper will find the log4j.xml in the Build directory -->
        &lt;pathelement location="Build"/>
        &lt;fileset dir="${tomcat.libs}">
               ....
        &lt;/fileset>
        &lt;pathelement location="${log4j.jar}"/>
        ....
    &lt;/path>
  
    &lt;taskdef name="jasper2" classname="org.apache.jasper.JspC" classpathref="jspc.classpath"/>
  &lt;/target>
  </pre>
  
  <p>I've verified that, in fact, the "Build" directory is at the front of the classpath and that a log4j.xml exists in that directory.  However, when I run ant in verbose mode with log4j in debug, I see that log4j is choosing the log4j.xml that is in the <em>current working directory</em>, which is not the one I want.  Log4j appears to not be using the classpath to resolve the default log4j.xml.</p>
  
  <p>I'm using log4j 1.2.8 (embedded within a larger framework, so I cannot upgrade it) and some of these taskdefs appear to rely on commons-logging 1.0.3.  The build process uses Sun Java 5.</p>
  
  <p>If I <code>set ANT_OPTS=-Dlog4j.configuration=Build/log4j.xml</code> before running ant, the taskdefs correctly load the desired log4j.xml.</p>
  
  <p>Putting the "Build" directory at the front of the classpath for the taskdefs used to work. I don't know what changed.  How can I restore the behavior where I can control -- within the build.xml -- which log4j configuration file is used for a given task?  Is there a way other than setting ANT_OPTS and other than rearranging files to move the application's log4j.xml out of the current working directory to get log4j to find the correct log4j.xml file?</p>