我正在尝试设置 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:PetProjectstimesheetbuild.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:PetProjectstimesheetbuild
[echo]
[echo]
[echo] compiling tests
[echo]
[echo]
[echo] C:PetProjectstimesheetbuildcommetimesheetexceptionsBadBlockException.class;C:PetProjectstimesheetbuildcommetimesheetpojoBlock.class;C:Installationsjunit-4.11.jar
[echo]
[echo]
[javac] C:PetProjectstimesheetbuild.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:PetProjectstimesheetbuild-test
[javac] C:PetProjectstimesheettestcommetimesheetpojoBlockTest.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:PetProjectstimesheettestcommetimesheetpojoBlockTest.java:11: package com.me.timesheet.exceptions does not exist
[javac] import com.me.timesheet.exceptions.BadBlockException;
您需要将目录C:PetProjectstimesheetbuild
放在类路径上,而不是单个类上。 所以当代码引用com.me.timesheet.pojo.Block
时,该类位于路径C:PetProjectstimesheetbuildcommetimesheetpojoBlock.class