下载:http://www.apache.org/dist/ant/binaries下的apache–ant-1.8.2-bin.zip
解压 设置环境变量
ANT_HOME D:\apache–ant-1.8.2; CLASSPATH .;%ANT_HOME%\lib; PATH ;%ANT_HOME\bin;
测试是否成功:cmd下输入ant -version
转载:http://hi.baidu.com/mystack/blog/item/cf07110098e6780b738b6559.html
注意:ant + junit eclipse->window->preferences->ant->runtime->ant home entries add jars junit.jar eclipse安装目录中有
build.xml内容如下:
<?xml version=”1.0″ encoding=”utf-8″?>
<project name=”study” default=”test” basedir=”.”>
<!–配置基本属性–>
<property name=”src.dir” value=”src” />
<property name=”classes.dir” value=”classes” />
<property name=”lib.dir” value=”lib” />
<property name=”dist.dir” value=”dist” />
<!–配置测试报告的属性–>
<property name=”report.dir” value=”report” />
<property name=”report.xml” value=”${report}/junit/xml” />
<property name=”report.html” value=”${report}/junit/html” />
<!–配置运行时classpath–>
<path id=”classpath.run”>
<pathelement path=”${classes.dir}” />
<fileset dir=”${lib.dir}”>
<include name=”*.jar” />
</fileset>
</path>
<!–配置测试时classpath–>
<path id=”classpath.test”>
<path refid=”classpath.run” />
<path location=”${dist}/lib/study.jar” />
</path>
<!–任务初始化–>
<target name=”init”>
<delete dir=”${classes.dir}” />
<delete dir=”${report.dir}” />
<delete dir=”${dist.dir}” />
<mkdir dir=”${classes.dir}” />
</target>
<!–配置编译任务–>
<target name=”compile” depends=”init” description=”compile source files”>
<javac srcdir=”${src.dir}” destdir=”${classes.dir}”>
<classpath refid=”classpath.run” />
</javac>
</target>
<!–配置打包任务–>
<target name=”dist” depends=”compile” description=”dist study.jar file”>
<mkdir dir=”${dist.dir}” />
<jar jarfile=”${dist.dir}/study.jar” basedir=”${classes.dir}” />
</target>
<!–配置运行任务–>
<!–
<target name=”run” depends=”compile, dist”>
<java classname=”com.test.TestCalculator”>
<classpath>
<path refid=”classpath.run” />
</classpath>
</java>
</target>
–>
<!–配置JUnit测试,打印测试结果–>
<target name=”test” depends=”compile, dist” description=”junit test!!!”>
<mkdir dir=”${report.xml}” />
<mkdir dir=”${report.html}” />
<junit printsummary=”yes” haltonfailure=”no”>
<classpath refid=”classpath.run” />
<formatter type=”xml” />
<batchtest fork=”yes” todir=”${report.xml}”>
<fileset dir=”${src.dir}” includes=”**/Test*.java” />
</batchtest>
</junit>
<junitreport todir=”${report.html}”>
<fileset dir=”${report.xml}”>
<include name=”*.xml” />
</fileset>
<report format=”frames” todir=”${report.html}” />
</junitreport>
</target>
</project>
转载于:https://blog.51cto.com/3449639/659945
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110558.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...