Ant:将类放在类路径上,但是没有看到它们

时间:2012-05-17 00:51:12

标签: java ant junit classpath

我正在尝试设置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;

1 个答案:

答案 0 :(得分:2)

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