我正在尝试让 Ant 编译我的项目,该项目具有以下目录结构:
MyProject/
src/main/java/
com/
<The rest of my source>
gen/
bin/
main/
<Where I want all Java sources compiled to>
lib/
main/
<All of my dependencies>
build.xml
build.properties
这是我的 Ant 任务:
<path id="src.main.java.path">
<fileset dir="src/main/java">
<include name="**.*java"/>
</fileset>
</path>
<path id="lib.main.path">
<fileset dir="lib/main">
<include name="**.*jar"/>
</fileset>
</path>
<target name="compile">
<javac includeantruntime="true" srcdir="src/main/java" destdir="gen/bin/main">
<!--
Define a new classpath composed of all main Java sources and main Java dependencies,
and use them for this compilation.
-->
<classpath>
<pathelement path="src.main.java.path"/>
<pathelement path="lib.main.path"/>
</classpath>
</javac>
</target>
我应该提到它build.xml
位于项目根目录,并且它的basedir
属性设置为"."
(项目根目录)。
当我运行“编译”任务时,我得到 100 多个编译器错误,它找不到我的任何项目依赖项(例如 Guice、Joda-Time、XStream 等):
compile:
[javac] Compiling 53 source files to /<path-to-my-project-root>/MyProject/gen/bin/main
[javac] /<path-to-my-project-root>/MyProject/src/main/java/org/me/Widget.java:37: package com.google.inject does not exist
[javac] import com.google.inject.AbstractModule;
[javac] ^
[javac] /<path-to-my-project-root>/MyProject/src/main/java/org/me/MyWidget.java:45: cannot find symbol
[javac] symbol: class AbstractModule
[javac] public class AppUziContext extends AbstractModule {
[javac]
BUILD FAILED
/<path-to-my-project>/MyProject/build.xml:51: Compile failed; see the compiler error output for details.
...列表中有 100 多个看起来像这样的错误,但对于它找不到的每个依赖项都是不同的。
我相信问题出在我配置并在里面引用的路径的某个地方javac/classpath
,但是在阅读了 Ant 文档之后,我无法弄清楚我要去哪里出错。提前致谢!