为ant junit任务指定junit.jar的备用名称

时间:2011-05-23 19:00:29

标签: ant junit

默认情况下JUnit jars在文件名中有版本号,例如 junit-4.8.2.jar The JUnit Ant Task只查找junit.jar。是否可以根据标准命名约定指定名称。我想这样做是因为我想在我的本地maven存储库中引用库。

1 个答案:

答案 0 :(得分:4)

实际上,JUnit任务文档为您提供了一些选择:

Note: You must have junit.jar available. You can do one of:

    Put both junit.jar and ant-junit.jar in ANT_HOME/lib.
    Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable.
    Add both JARs to your classpath using -lib.
    Specify the locations of both JARs using a <classpath> element in a <taskdef> in the build file.
    Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the <classpath> passed to <junit>. (since Ant 1.7)

修改

这就是你需要的。

<junit
   ...
>
  <classpath>
    <pathelement location="/path/to/your/custom/junit-4.8.2.jar""/>
    <path refid="your.other.classpath.dependencies" />
  </classpath>
  ...
</junit>