java - Ant:将类放在类路径中,但看不到它们

标签 java ant junit classpath

我正在尝试设置 Ant 来运行我的测试,但我的测试无法编译。 错误是它找不到我正在测试的类,即使我将它们放在类路径中。我什至输出了类路径,它们就在上面。

Ant :

<target name="compile">
    <echo>compiling code</echo>
    <javac debug="true" srcdir="${src}" destdir="${build}" classpathref="build.path" />

    <echo>compiling tests</echo>

    <echo message="${toString:build.test.path}" />

    <javac debug="true" srcdir="${test}" destdir="${build.test}" classpathref="build.test.path" />
</target>
<path id="build.test.path">        
    <fileset dir="${build}">
        <include name="**/*.class"/>
    </fileset>
    <fileset dir="${install}">
        <include name="junit-4.11.jar"/>
    </fileset>
</path>

这是控制台输出:

compile:
 [echo] compiling code
[javac] C:\PetProjects\timesheet\build.xml:37: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 2 source files to C:\PetProjects\timesheet\build
 [echo]
 [echo]
 [echo] compiling tests
 [echo]
 [echo]
 [echo] C:\PetProjects\timesheet\build\com\me\timesheet\exceptions\BadBlockException.class;C:\PetProjects\timesheet\build\com\me\timesheet\pojo\Block.class;C:\Installations\junit-4.11.jar
 [echo]
 [echo]
[javac] C:\PetProjects\timesheet\build.xml:47: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to C:\PetProjects\timesheet\build-test
[javac] C:\PetProjects\timesheet\test\com\me\timesheet\pojo\BlockTest.java:9: cannot find symbol
[javac] symbol  : class Block
[javac] location: package com.me.timesheet.pojo
[javac] import com.me.timesheet.pojo.Block;
[javac]                               ^
[javac] C:\PetProjects\timesheet\test\com\me\timesheet\pojo\BlockTest.java:11: package com.me.timesheet.exceptions does not exist
[javac] import com.me.timesheet.exceptions.BadBlockException;

最佳答案

您需要将目录 C:\PetProjects\timesheet\build 放在类路径中,而不是各个类。因此,当代码引用 com.me.timesheet.pojo.Block 时,该类位于路径 C:\PetProjects\timesheet\build\com\me\timesheet\pojo\Block .class

关于java - Ant:将类放在类路径中,但看不到它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628607/

相关文章:

sql - ant sql任务类路径问题

regex - Ant replaceregexp 任务 - 匹配和替换 HTML 注释 block

java - 如何使用 JUnit 测试异步进程

java - 无法在 Maven 中使用 Selenium 连接到二进制 FirefoxBinary

apache - Apache Ant 如何解决重复目标

junit - 模拟外部不可见的依赖项

java - 自底向上归并排序的实现中是否存在可能的勘误表

java - 当交易超时时如何执行一些操作

java - 有什么理由在 LogBack Logger 上使用 private 而不是 private final static?

java - 此函数调用中的参数无法理解