gpt4 book ai didi

java - AntBuilder 找不到包 org.junit

转载 作者:行者123 更新时间:2023-12-02 07:31:34 26 4
gpt4 key购买 nike

我使用“JUnit 测试用例”新文件对话框将一些单元测试添加到 Eclipse 项目的测试目录(与我的 src 目录平行)中。我有两个构建器,默认的 Java 构建器和我添加的 AntBuilder。 Java Builder 继续工作,但 AntBuilder 在 Eclipse 中失败。当我选择“项目”->“构建全部”时,它会显示以下内容:

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>

关于java - AntBuilder 找不到包 org.junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12848688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com