【发布时间】:2012-02-17 15:19:23
【问题描述】:
我正在构建一个 Ant 构建文件,它在我的 eclipse 项目中正常工作,但在我们的 Jenkins 自动构建设置中却没有。我在我的计算机上安装了 ant 并从控制台运行了构建。它有效,但我意识到它没有像我希望的那样在我的项目库中使用 junit-4.10.jar,而是在 ant 库中使用 junit.jar。在我的 ant 库中重命名 junit.jar 文件后,ant 构建不起作用。
所以基本上我们的 Jenkins 自动构建设置中的问题是它自己的 ant lib 目录中没有 junit.jar。我可以指定 junit 任务以使用项目库中的 jar 而不是 ant 库中的 jar 吗?
编辑:我已经修改了我的 build.xml 文件,现在看起来像这样,仍然无法正常工作。我的 junit-4.10.jar 在 /war/WEB-INF/lib/test 目录下:
<project name="vlp" default="junit" basedir=".">
<tstamp />
<!-- ################# PROPERTIES ################ -->
<!-- directory properties -->
<!-- source -->
<property name="vlp.src" location="src" />
<property name="vlp.test" location="test" />
<!-- build -->
<property name="src.build" location="bin/src" />
<property name="test.build" location="bin/test" />
<!-- libraries -->
<property name="vlp.lib.dir" location="war/WEB-INF/lib" />
<property name="vlp.testlib.dir" location="war/WEB-INF/lib/test" />
<!-- compile classpath -->
<path id="compile.path">
<fileset dir="${vlp.lib.dir}" includes="*.jar" />
</path>
<!-- test classpath -->
<path id="test.path">
<fileset dir="${vlp.testlib.dir}" includes="*.jar" />
<path refid="compile.path" />
</path>
<!-- ############### CLEANING ################## -->
<!-- Cleaning old compile files -->
<target name="clean" description="Clean all the old build files.">
<delete dir="${src.build}" />
<delete dir="${dist}" />
</target>
<!-- ############## COMPILATION ############### -->
<!-- Compile source -->
<target name="src.compile" depends="clean" description="Compile the source code when everything has been cleaned.">
<mkdir dir="${src.build}" />
<javac encoding="utf-8" destdir="${src.build}" nowarn="true">
<src path="${vlp.src}" />
<classpath refid="compile.path" />
</javac>
</target>
<!-- Compile test -->
<target name="test.compile" depends="clean" description="Compile the source code when everything has been cleaned.">
<mkdir dir="${test.build}" />
<javac encoding="utf-8" destdir="${test.build}" nowarn="true">
<src path="${vlp.test}" />
<classpath>
<pathelement location="${src.build}" />
<path refid="test.path" />
</classpath>
</javac>
</target>
<!-- ########### RUNS JUNIT TEST ############ -->
<target name="junit" depends="src.compile,test.compile" description="Runs all the unit test in the application. Does not halt build if test are failed.">
<junit printsummary="on" haltonfailure="false" showoutput="true">
<formatter type="brief" usefile="false" />
<classpath>
<pathelement location="${test.build}" />
<path refid="test.path" />
</classpath>
<batchtest>
<fileset dir="${vlp.test}">
<include name="**/Test*.java" />
<exclude name="**/AllTests.java" />
</fileset>
</batchtest>
</junit>
</target>
</project>
编辑:可以在here 找到类似的问题,但答案不同,效果很好。请注意,在机器上安装 ant-junit 比尝试将其添加到您的库和所有内容中要容易得多。
【问题讨论】: