Ant无法识别Log4j.properties文件

时间:2012-01-25 18:30:36

标签: ant junit log4j

过去两天我一直对这个问题感到震惊。请帮助我。我正在使用ANT运行我的JUNIT脚本。正在生成报告,但ANT无法找到我的log4j.properites文件。当我在eclipse中运行时,正在生成日志。我的问题是我在运行ANT.DO时需要日志我需要设置任何属性。 我在做什么错误?

请帮帮我。


我的日志:

#Application Logs
#log4j.logger.devpinoyLogger
log4j.rootLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=/Users/Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false

build.xml


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>

<project name="Module_Junit_Ant" default="usage" basedir=".">  

<!-- ========== Initialize Properties =================================== -->
    <property environment="env"/>

    <property name="ws.home" value="${basedir}"/>
    <property name="ws.jars" value="${ws.home}/jars"/>
    <property name="test.dest" value="${ws.home}/build"/>
    <property name="test.src" value="${ws.home}/src"/>
    <property name="test.reportsDir" value="${ws.home}/reports"/>



    <path id="testcase.path">


        <pathelement location="${test.dest}"/>

        <fileset dir="${ws.jars}">
          <include name="*.jar"/>
        </fileset>

      </path>


    <!--target name="start-selenium-server">
        <java jar="${ws.home}/lib/selenium-server.jar"/>
    </target-->

    <target name="setClassPath" unless="test.classpath">
        <path id="classpath_jars">
            <fileset dir="${ws.jars}" includes="*.jar"/>
            <fileset dir="${test.src}" includes="*.properties"/>
        </path>
        <pathconvert pathsep=":" 
            property="test.classpath" 
            refid="classpath_jars"/>
    </target>

    <target name="init" depends="setClassPath">
        <tstamp>
            <format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
        </tstamp>
        <condition property="ANT" 
            value="${env.ANT_HOME}/bin/ant.bat" 
            else="${env.ANT_HOME}/bin/ant">
                    <os family="windows" />
        </condition>

    </target>

    <!-- all -->
    <target name="all">
    </target>

    <!-- clean -->
    <target name="clean">
        <delete dir="${test.dest}"/>
    </target>

    <!-- compile -->
    <target name="compile" depends="init, clean" > 
        <delete includeemptydirs="true" quiet="true">
            <fileset dir="${test.dest}" includes="**/*"/>
        </delete>
        <echo message="making directory..."/>
        <mkdir dir="${test.dest}"/>
        <echo message="classpath------: ${test.classpath}"/>
        <echo message="compiling..."/>
        <javac 
            debug="true" 
            destdir="${test.dest}" 
            srcdir="${test.src}" 
            target="1.5" 
            classpath="${test.classpath}"
        >
        </javac>
      </target>

    <!-- build -->
    <target name="build" depends="init">
    </target>




    <target name="usage">
        <echo>
            ant run will execute the test
        </echo>
    </target>

    <path id="test.c">
            <fileset dir="${ws.jars}" includes="*.jar"/>
    </path>



    <target name="run" >  
        <delete includeemptydirs="true" quiet="true">
                    <fileset dir="${test.reportsDir}" includes="**/*"/>
                </delete>
                <java jar="${ws.jars}" fork="true" spawn="true" />  
                <junit fork="yes" haltonfailure="no" printsummary="yes">
                    <classpath refid="testcase.path" />  

                  <!--  <classpath ="${test.classpath}"/> -->  
                <batchtest  todir="${test.reportsDir}" fork="true">  
                <fileset dir="${test.dest}">  

                    <include name="LogTest.class" />
                    <!--include name="tests/suite1/FirstSuiteRunner.class" />
                    <include name="tests/suite1/FirstSuiteRunner.class" /-->


                </fileset>  
                </batchtest>    
                    <formatter type="xml" />  
                    <classpath refid="testcase.path" />  
            </junit>  
                <junitreport todir="${test.reportsDir}">    
                    <fileset dir="${test.reportsDir}">  
                        <include name="TEST-*.xml" />  
                    </fileset>  
                    <report todir="${test.reportsDir}" />  
                </junitreport>  
            </target>

        <target name="email" >
               <java classname="util.SendMail" classpath="${test.dest}" classpathref="testcase.path" />
        </target>


</project>

1 个答案:

答案 0 :(得分:0)

您的log4j.properties位于何处? 什么对我有用呢

< pathelement location="x/y/z"/>

里面的

< path id="testcase.path">

指向包含log4j.properties的文件夹! 所以在这个例子中你的log4j.properties应该在'z'文件夹里面!