4

I am trying to set up Ant to run my tests, but my tests fail to compile. The error is that it can't find the classes I am testing, even though I put them on the classpath. I even output the classpath and they are on it.

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>

This is the console output:

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;
4

1 に答える 1

2

C:\PetProjects\timesheet\buildディレクトリは、個々のクラスではなく、クラスパスに配置する必要があります。したがって、コードがを参照するcom.me.timesheet.pojo.Block場合、クラスはパス上にありますC:\PetProjects\timesheet\build\com\me\timesheet\pojo\Block.class

于 2012-05-17T01:01:03.310 に答える