Ant 类路径和 junit.jar [英] Ant classpath and junit.jar

查看:22
本文介绍了Ant 类路径和 junit.jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 build.xml,它允许我运行 junit 测试.这是相关部分:

I have the an build.xml that allows me to run junit tests. Here is the relevant part:

<path id="JUnit 4.libraryclasspath">
    <pathelement location="../../../../../eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>
    <pathelement location="../../../../../eclipse/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/>
</path>
<path id="MyProject.classpath">
    <pathelement location="bin"/>
    <path refid="JUnit 4.libraryclasspath"/>
</path>

<target name="run_unit_tests" depends="build">
        <mkdir dir="${junit.output.dir}"/>
        <junit printsummary="yes" haltonfailure="no">   
            <classpath refid="MyProject.classpath" />

            <formatter type="xml"/>
            <batchtest todir="${junit.output.dir}">
                    <fileset dir="${src}">
                            <include name="**/*Test*.java"/>
                    </fileset>
            </batchtest>
        </junit>
</target>

如果我替换该行:

<pathelement location="../../../../../eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>

<pathelement location="${eclipse.home}/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>

更改破坏了类路径.我收到以下错误:

The change breaks the classpath. I get the following error:

必须如果不是 Ant 自己的,则包含 junit.jar类路径

The <classpath> for <junit> must include junit.jar if not in Ant's own classpath

据我所知,位置属性在两种情况下都应该保持相同的值.那么可能是什么原因呢?

As far as I understand, the location attribute should hold the same value in both cases. So what can be the reason?

作为一个附带问题,此构建文件将无法在具有不同 junit 版本的环境中运行(路径会中断).是否可以向 junit.jar 添加通用"路径?

As a side question, this build file will not work on an environment with different junit version (the path will break). Is it possible to add a "general" path to junit.jar?

推荐答案

JUnit 库驻留在您指定的任何位置.就个人而言,我会完全忘记链接 Eclipse 附带的 jar 文件,而是直接下载 jars.

The JUnit library resides wherever you tell it to reside. Personally, I would forget entirely about linking against the jar files shipped with Eclipse and instead download the jars directly.

如果我有一个项目,比如在路径 /project 然后我会尝试将依赖项放在该层次结构中的某个位置,例如 /project/test/lib/junit.jar.如果我的 ant 构建文件是 /project/build.xml 那么它就像将 ./test/lib/junit.jar 添加到 JUnit 类路径一样简单.尝试引用您机器上的任意位置是脆弱的(请记住,Eclipse 可以安装任何地方),尤其是在使用相对路径时(因为您的项目内容可以被存储任何地方).

If I have a project, say at path /project then I would try to put the dependency somewhere in that hierarchy, like at /project/test/lib/junit.jar. If my ant build file is then /project/build.xml then it's as simple as adding ./test/lib/junit.jar to the JUnit classpath. Trying to reference an arbitrary location on your machine is fragile (remember, Eclipse could be installed anywhere), particularly when using relative paths (since your project contents could also be stored anywhere).

这篇关于Ant 类路径和 junit.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆