为什么 ANT javac 任务一次又一次地重新编译我的 .java

发布于 2024-12-18 02:15:40 字数 870 浏览 4 评论 0原文

将递归扫描源目录和目标目录 要编译的 Java 源文件。仅 Java 文件没有 相应的 .class 文件或类文件早于 .java 文件将被编译。

以上内容来自javac Task,ANT Apache。但我真的不明白为什么在我的例子中 .java 会一次又一次地重新编译。

我的工作目录是.../trunk

我的源文件(.java)位于 trunk/src

我的目标文件(.class)位于 trunk/bin

我的.java 文件使用默认包,即没有包声明。

javac 任务在

<javac srcdir="${src}"
   destdir="${bin}"
   includeantruntime="false">
  <classpath>
<pathelement location="${bin}"/>    
<pathelement path="${java.class.path}"/>
  </classpath>
</javac>

我定义的

<property name="src"    value="src"/>
<property name="bin"    value="bin/"/>

build.xml 中以这种方式使用似乎一切正常,但每次我运行 ANT 时,它都会重新编译 .java 文件。真是奇怪啊!有人愿意告诉我为什么吗?谢谢。

The source and destination directory will be recursively scanned for
Java source files to compile. Only Java files that have no
corresponding .class file or where the class file is older than the
.java file will be compiled.

The above is from javac Task, ANT Apache. But I really don't see why in my case .java is recompiled again and again.

My working directory is .../trunk

My source (.java) is located at trunk/src

My target (.class) is located at trunk/bin

My .java files use default package, namely, no package declaration.

The javac task is used this way in my build.xml

<javac srcdir="${src}"
   destdir="${bin}"
   includeantruntime="false">
  <classpath>
<pathelement location="${bin}"/>    
<pathelement path="${java.class.path}"/>
  </classpath>
</javac>

where I have defined

<property name="src"    value="src"/>
<property name="bin"    value="bin/"/>

It seems everything is ok, but each time I run ANT, it recompiles the .java files. Really strange! Anyone would like to tell me why? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小清晰的声音 2024-12-25 02:15:40

哦,我得到了答案。抱歉我没有把上面的故事全部讲完。实际上,在“javac”部分之前我有一个 antlr 词法分析器/解析器生成。为此,我应该添加“-make”选项,以便词法分析器和解析器不会使用更新的时间戳再次生成。 (来自 将 ANT 用于 ANTLR3< /a>

ANLTR3 命令行选项“-make”仅在以下位置生成新文件
如果它们比语法更古老。这种行为可能会产生
对“编译”等依赖任务的影响,这可能会导致
无需处理任何内容,因为它是最新的。

Oh, I got the answer. Sorry I did not tell all the story above. Actually, I have an antlr lexer/parser generation before the "javac" part. And for that, I should have added the "-make" option so that the lexer and parser will not be generated again with a more recent timestamp. (from Use ANT for ANTLR3

The ANLTR3 command-line option "-make" only generates new files in
case they are older than the grammar. This behaviour might have an
effect on dependent tasks like "compile", which could result in
nothing to be processed because it is up to date.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文