Java – how to compile only changed source files using ant

I'm trying to write an ant build for compiling the source folder, which is the target of my compiled script

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

    </target>

In my project, I have about 1000 Java file When changing a single Java files, the target will often compile all Java file This makes development very slow I just want to know if there is any method or code to change the behavior of the task, just compile, modify or change Java files, not all Java file

Please help me

Solution

As far as I know, compiling only modified java files is the default behavior of ant javac task Ant uses Java file timestamp and its corresponding Class file to determine whether java files need to be recompiled I have used it in many projects and have never had a problem

Here are some things you can see

>Does your source tree directory structure match the java package structure? See why does ant always recommend all my java files This may be the first reason in the FAQ. > I see that your compilation target depends on the init target? What does the init target do? It depends on any clean target or clean - up Class file? > What is your ant version? You can try different ant versions to see if you have the same problem? > If none of the above can solve your problem, can you check manually after compiling Class file timestamp and compare it with the corresponding Compare timestamps of java files?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>