gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:27:13 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com