天天看點

解決ant編譯中出現“includeantruntime was not set”警告的問題

執行ant編譯時,總會出現如下的警告:

[javac] D:\SnowPad\build.xml:26: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

雖然不影響編譯,但還是解決才安心。其實解決方法也很簡單,隻需要根據提示在javac任務中添加includeAntRuntime="false"屬性即可。例如:

修改前:

    <javac srcdir="${srcDir}" destdir="${binDir}" />

修改後:

    <javac srcdir="${srcDir}" destdir="${binDir}" includeAntRuntime="false" />

注:

1.對于includeAntRuntime屬性,官方的解釋如下:

    Whether to include the Ant run-time libraries in the classpath; defaults to yes, unless build.sysclasspath is set. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run.

2.此警告在較早的ant版本中可能不會出現,目前用的版本是:Apache Ant(TM) version 1.8.2 compiled on December 20 2010。是以此問題跟ant版本有關。

build.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- one project with multiple targets  -->

<project name="test" default="run" basedir="." >

    <!-- paths used -->

    <property name="src.dir" value="src" />  <!--src代碼放在位置 -->

    <property name="dest.dir" value="build" /> <!-- class 生成位置最好建立該檔案 -->

    <property name="dest.report" value="report" />

    <path id="jarfile">  <!-- 需要的jar包放進入 -->

        <fileset dir="lib" includes="testng-6.5.1.jar" />

        <fileset dir="lib" includes="selenium-server-standalone-2.49.0.jar"/>

    </path>

    <!-- delete the output folder if it exists -->

    <delete dir="${dest.dir}" failonerror="false" />

    <!-- create the output folder -->

    <mkdir dir="${dest.dir}" />

    <mkdir dir="${dest.report}" />

    <!-- target to compile all test classes out -->

    <target name="build">

        <!-- do copy -->

        <!-- compile -->

        <javac srcdir="${src.dir}" destdir="${dest.dir}" encoding="UTF-8" debug="true" fork="yes"  includeAntRuntime="false" >

            <classpath refid="jarfile"  />

        </javac>

    </target>

    <!-- define the TestNG task -->

    <taskdef name="testng" classname="com.beust.testng.TestNGAntTask" classpathref="jarfile" />

    <!-- run test -->

    <target name="run" depends="build">

        <testng classpathref="jarfile" outputDir="${dest.report}" haltOnFailure="false">

            <classfileset dir="${dest.dir}" includes="*.class" />

            <classpath>

                <pathelement path="${dest.dir}" />

            </classpath>

            <xmlfileset dir="${basedir}" includes="testng.xml" />

        </testng>

</project>

本文轉自 知止内明 51CTO部落格,原文連結:http://blog.51cto.com/357712148/1891279,如需轉載請自行聯系原作者