如何从Ant开始的Java类中看到Log4J输出?

luc*_*ell 3 ant log4j

通过Ant运行Java类时,我在获取Log4J输出时遇到了很多麻烦,即使log4.properties在类路径上也是如此.在这里记录它,以防其他人有同样的问题.

例如

<java classname="Hello" fork="true">      
    <classpath> 
    <fileset dir="${lib.dir}">
        <include name="**/*.jar"/>
    </fileset>     
    </classpath>
</java>
Run Code Online (Sandbox Code Playgroud)

luc*_*ell 6

这可以通过以下方式解决:

<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>
Run Code Online (Sandbox Code Playgroud)