如何使用 ANT 仅编译更改的源文件 [英] how to compile only changed source files using ANT

查看:27
本文介绍了如何使用 ANT 仅编译更改的源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写用于编译源文件夹的 ant build,这里是我用于编译的脚本 target.

I am trying to write ant build for compiling source folder here is my script target for compiling.

 <target name="compile" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true">
            <classpath refid="master-classpath"/>
        </javac>

    </target>

在我的项目中,我有将近 1000 个 .java 文件.当单个 .java 文件在目标之上更改时,往往会编译所有 .java 文件.这使得开发非常缓慢.我只想知道有什么方法或代码可以改变任务的行为,只编译修改或更改的 .java 文件而不是所有的 .java 文件.

In my project I have near about 1000 .java files. When ever a single .java file is changed above target tends to compile all .java files. Which make development very slow. I just want to know is there any way or code to change the behavior of task to compile only modified or changed .java file rather than all .java file.

请帮帮我.

推荐答案

据我所知,只编译修改后的 java 文件是 ant javac 任务的默认行为.Ant 使用 .java 文件的时间戳及其对应的 .class 文件来确定是否需要重新编译 Java 文件.我已经在很多项目中使用过它,从来没有出现过问题.

As I understand, compiling only the modified java files is the default behavior of ant javac task. Ant uses the timestamp of a .java file and its corresponding .class file to determine if the a Java file needs to be recompiled. I have used it in many projects and never have issues.

以下是您可以检查的一些事项

Here are a few things you can check

  1. 您的源代码树目录结构是否与您的 Java 包匹配结构体?请参阅 为什么 ant 总是重新编译我所有的 Java文件?.这可能是第一大原因,因为它在常见问题解答中.

  1. Is your source tree directory structure matching your Java package structure? Please see Why does ant always recompile all my Java files?. This is probably the number 1 reason since it is in the FAQ.

我看到你的 compile 目标依赖于 init 目标?init 目标有什么作用?它依赖于任何 clean 目标还是清理 .class 文件?

I see your compile target depends on init target? What does the init target do? Does it depends on any clean target or does it cleanup the .class files?

你的蚂蚁版本是什么?能不能换个ant版本试试看是不是还是一样的问题?

What is your ant version? Can you try a different ant version to see if you still have the same problem?

如果以上都不能解决您的问题,编译后,您能否手动检查.class文件的时间戳并与对应的.java文件的时间戳进行比较?

If none of the above fixes your issue, after the compilation, can you manually check the .class file timestamp and compare it with the timestamp of the corresponding .java file?

这篇关于如何使用 ANT 仅编译更改的源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆