tags:

views:

56

answers:

2

When running a Java class through Ant, I was having a lot of trouble getting Log4J output, even though the log4.properties was on the classpath. Documenting it here in case anyone else has the same problem.

E.g.

<java classname="Hello" fork="true">      
    <classpath> 
    <fileset dir="${lib.dir}">
        <include name="**/*.jar"/>
    </fileset>     
    </classpath>
</java>
+2  A: 

This can be solved using something like the following:

<property name="log4j" value="file:///${basedir}/log4j.properties"/>
...
<java classname="Hello" fork="true">   
    <sysproperty key="log4j.configuration" value="${log4j}"/>
    <classpath> 
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>     
    </classpath>
</java>
lrussell
+1  A: 

If you're curious to see where log4j is looking for it's configuration files, try setting the log4j.debug system property.

<java classname="Hello" fork="true">
  <sysproperty key="log4j.debug" value="true" />
  <classpath>
    …
  </classpath>
</java>

That will print information on stderr saying where it's looking for it's configuration files. There's a brief mention of this in the manual.

Dominic Mitchell