我有一个 Ant 构建可以正确编译我的主类,但是在编译我的测试类时失败,因为它找不到我的任何主类的符号:
项目目录结构:
MyProj/
src/
main/
java/
resources/
test/
java/
resources/
build/
build.properties
build.xml
gen/
lib/
main/
test/
bin/
main/
test/
(虽然它具有 Maven 项目的结构,但它不是。它是基于 Ant 的构建。我只是喜欢 Maven 组织项目的方式。)
build.properties
src.main.java.dir=src/main/java
src.test.java.dir=src/test/java
gen.dir=gen
gen.bin.dir=${gen.dir}/bin
gen.bin.main.dir=${gen.bin.dir}/main
gen.bin.test.dir=${gen.bin.dir}/test
gen.lib.dir=${gen.dir}/lib
gen.lib.main.dir=${gen.lib.dir}/main
gen.lib.test.dir=${gen.lib.dir}/test
build.xml
<project name="MyProj" default="deploy" basedir="..">
<property environment="env" />
<property file="build/build.properties" />
<!-- Sourcepath for main Java source. -->
<path id="src.main.path">
<fileset dir="${src.main.java.dir}">
<include name="**.*java"/>
</fileset>
</path>
<!-- Sourcepath for test Java source. -->
<path id="src.test.path">
<fileset dir="${src.test.java.dir}">
<include name="**.*java"/>
</fileset>
</path>
<!-- Path for main Java dependencies. -->
<path id="lib.main.path">
<fileset dir="${gen.lib.main.dir}">
<include name="**.*jar"/>
</fileset>
</path>
<!-- Path for test Java dependencies. -->
<path id="lib.test.path">
<fileset dir="${gen.lib.test.dir}">
<include name="**.*jar"/>
</fileset>
</path>
<!-- Main compile path. -->
<path id="main.compile.path">
<path refid="src.main.path"/>
<path refid="lib.main.path"/>
</path>
<!-- Test compile path. -->
<path id="test.compile.path">
<path refid="src.test.path"/>
<path refid="src.main.path"/>
<path refid="lib.test.path"/>
<path refid="lib.main.path"/>
</path>
<!-- Compile main Java sources. -->
<target name="compile-main">
<echo message="Compiling main sources." />
<javac includeantruntime="false" srcdir="${src.main.java.dir}" destdir="${gen.bin.main.dir}">
<classpath refid="main.compile.path"/>
</javac>
</target>
<!-- Compile test Java sources. -->
<target name="compile-test" depends="compile-main">
<echo message="Compiling test sources." />
<javac includeantruntime="false" srcdir="${src.test.java.dir}" destdir="${gen.bin.test.dir}">
<classpath refid="test.compile.path"/>
</javac>
</target>
</project>
当我运行时,compile-main
我收到一条BUILD SUCCESSFUL
消息(它构建得很好)。但是当我运行时compile-test
,我遇到了 100 多个错误,如下所示:
[javac] /home/myUser/sandbox/workbench/eclipse/workspace/MyProj/src/test/java/com/myproj/server/SomeTest.java:79: cannot find symbol
[javac] symbol : variable Widget
[javac] location: class com.myproj.server.SomeTest
[javac] Widget.Always,
[javac] ^
[javac] 100 errors
BUILD FAILED
/home/myUser/sandbox/workbench/eclipse/workspace/MyProj/build/build-local.xml:163: Compile failed; see the compiler error output for details.
Widget
是一个主类(枚举)并且有一个Always
值。
我已经检查并重新检查了我的路径。对于我的生活,我无法弄清楚为什么我test.compile.path
找不到我的主要代码。提前致谢。