首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ant中的Junit类路径: dirset的问题

ant中的Junit类路径: dirset的问题
EN

Stack Overflow用户
提问于 2012-03-27 18:18:07
回答 1查看 587关注 0票数 0

我在尝试使用时遇到了麻烦

代码语言:javascript
复制
<dirsets>

在我的车里。这是类路径的代码片段。

代码语言:javascript
复制
<target name="myTests" >     
    <junit haltonerror="true" haltonfailure="true" fork="true">
        <classpath>
            <dirset dir="/my/absolute/root/path/where/I/keep/compiled/classes">
                <include name="com/mycompany/mytests"/>
                </dirset>
                <pathelement location="my/path/to/jars/myjar1.jar" />  
                <pathelement location="my/path/to/jars/myjar2.jar" />  
                <!-- and so on -->  
             </classpath>
    <test name="com.mycompany.mytests.MyFirstTest" 
               outfile="${dir.report.test}/report_MyFirstTest">
                <formatter type="xml" />
</test> 
    </junit>
   </target> 

当我启动测试时,在成功编译完所有代码后,ant抱怨:

代码语言:javascript
复制
java.lang.ClassNotFoundException: com.mycompany.mytests.MyFirstTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)

我尝试了绝对路径和相对路径,但从来都不起作用。我的类路径由许多jars组成,这些jars是用many指定的,并且永远不会被识别。我的错在哪里?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2012-03-27 20:02:07

以前,当我使用ant时,我使用嵌套的元素,并使用path-like结构指定类路径-如下所示:

代码语言:javascript
复制
<path id="project.test.classpath">
    <pathelement location="/my/absolute/root/path/where/I/keep/compiled/classes" />
    <fileset dir="/my/path/to/jars">
        <include name="**/*.jar" />
    </fileset>
</path>


<target name="myTests">
    <junit haltonerror="true" haltonfailure="true" fork="true">
        <classpath refid="project.test.classpath" />
        <test name="com.mycompany.mytests.MyFirstTest" outfile="${dir.report.test}/report_MyFirstTest">
            <formatter type="xml" />
        </test>
    </junit>
</target> 

也许这也适合你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9887572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档