我在 Eclipse 的项目中使用“JUnit 测试用例”新文件对话框向测试目录(与我的 src 目录平行)添加了一些单元测试。我有两个构建器,默认的 Java 构建器和我添加的 AntBuilder。Java Builder 继续工作,但 AntBuilder 在 Eclipse 中失败。当我选择 Project -> Build All 时,它会显示:
Buildfile: C:\source\machine-paint\eclipse\machine-paint\src\build.xml
clean:
[delete] Deleting directory C:\source\machine-paint\eclipse\machine-paint\build
compile:
[mkdir] Created dir: C:\source\machine-paint\eclipse\machine-paint\build\classes
[javac] Compiling 33 source files to C:\source\machine-paint\eclipse\machine-paint\build\classes
[javac] C:\source\machine-paint\eclipse\machine-paint\test\stencil\BorderWalkerTest.java:3: error: package org.junit does not exist
[javac] import static org.junit.Assert.*;
[javac] ^
然后在一些类似的错误之后,这个:
[javac] C:\source\machine-paint\eclipse\machine-paint\test\stencil\BorderWalkerTest.java:8: error: incompatible types
[javac] @Test
[javac] ^
[javac] required: Annotation
[javac] found: Test
这是我的构建文件。在这一点上,我真的在黑暗中开枪,例如将那个类路径标记添加到 javac 命令。
<?xml version="1.0" encoding="UTF-8"?>
<project name="Builder" default="jar" basedir=".">
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="build/classes" />
<javac srcdir="." destdir="build/classes" debug="true" includeantruntime="true">
<classpath>
<path id="org.junit" location="c:/eclipse/plugins/org.apache.ant_1.8.3.v20120321-1730/lib/junit.jar" />
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="../../stencil.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="stencil.Main" />
</manifest>
</jar>
<copy file="../../stencil.jar" tofile="../../../robotsdoart/stencils/stencil.jar" />
</target>
<target name="run">
<java jar="build/jar/stencil.jar" fork="true" />
</target>
</project>