如何解决"原因:找不到类org.apache.tools.ant.taskdefs.optional.junit.JUnitTask." 在运行"蚂蚁测试"?

xia*_*012 21 ant junit

我有一个名为test的目标,我想做一些测试.

我把这里的重要部分放在build.xml中.这包括:

<property name='lib.dir' value='lib' />

<path id='classpath'>
     <fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
Run Code Online (Sandbox Code Playgroud)

我在lib目录中放了junit.jarant-junit.jar(它是必须的吗?).

但是,如果我跑

ant test.

输出错误是:

test:

BUILD FAILED
/home/xiaohan/EclipseWorkSpace/AntTest/build.xml:82: Problem: failed to create task or type junit
Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -/usr/share/ant/lib
        -/home/xiaohan/.ant/lib
        -a directory added on the command line with the -lib argument

Do not panic, this is a common problem.
The commonest cause is a missing JAR.

This is not a bug; it is a configuration problem
Run Code Online (Sandbox Code Playgroud)

另外,如果我将两个jar文件放在带有$ ANT_HOME设置的/ usr/share/ant/lib中,它仍然无效.

非常感谢任何提示

Luc*_*rin 32

就我而言(使用Mint,基于Debian)

sudo apt-get install ant-optional
Run Code Online (Sandbox Code Playgroud)

是唯一有用的东西.


nul*_*ull 17

安装ant-junit后,基于RHEL的系统解决了这个问题:

$ sudo yum install ant-junit
Run Code Online (Sandbox Code Playgroud)


Thr*_*esh 4

<property name='lib.dir' value='lib' />

<path id='classpath'>
    <fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
Run Code Online (Sandbox Code Playgroud)

这与 Ant 类路径本身无关。它是您可以在任务中使用的属性。您必须将 jar 放入建议的目录或添加命令行参数。

尝试像这样运行它:

ant -lib /path/to/the/ant-junit.jar/ test
Run Code Online (Sandbox Code Playgroud)

  • ant -lib 需要一个目录,而不是一个文件 (4认同)