AntBuilder找不到包org.junit
我在Eclipse的项目中使用“JUnit测试用例”新文件对话框将一些单元测试添加到测试目录(与我的src目录并行)。我有两个构建器,默认的Java Builder和我添加的AntBuilder。 Java Builder继续工作,但AntBuilder在Eclipse中失败。当我选择项目 - >生成所有,它会显示这样的:AntBuilder找不到包org.junit
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>
回答:
尝试将srcdir更改为实际源目录,以便它不包含测试。
喜欢的东西:
<javac srcdir="src/" 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" /> <!-- not sure if you need this -->
</classpath>
</javac>
回答:
尝试直接包括您的junit
jar文件。还要确保JAR文件在该位置可用。
<javac srcdir="."
destdir="build/classes"
debug="true"
includeantruntime="true"
classpath="c:/eclipse/plugins/org.apache.ant_1.8.3.v20120321-1730/lib/junit.jar"
/>
或定义path
元素:
<path id="lib.path.id"> <fileset dir="c:/eclipse/plugins/org.apache.ant_1.8.3.v20120321-1730/lib"
includes="junit.jar"/>
</path>
,并使用相同的javac
为
<javac srcdir="."
destdir="build/classes"
debug="true"
includeantruntime="true"
classpathref="lib.path.id""
/>
希望这有助于。
以上是 AntBuilder找不到包org.junit 的全部内容, 来源链接: utcz.com/qa/262288.html