简体   繁体   中英

Java Ant Performance when deleting directory

Hello fellow stackoverflowers,

Most Ant build files I've seen online involve a "clean" target that always removes a directory using deltree and recreates that directory, where all the binaries will be outputted to. Is this a performance problem? That is, a source file should only be compiled if it has been changed, but if the directory holding all the binaries is deleted after every build, then all files have to be recompiled on each build. Is this what happens, and if so, am I wrong in saying that this could really hurt performance.

As a follow up question, is doing this absolutely necessary or highly recommended when using Ant? My team happens to be using dropbox to sync to multiple machines, and we may not want this step to occur on every run.

Thanks for any input!

-alanhorizon

You can often avoid the clean step and javac will only compile changes. For rapid development you can probably get away with it and just run clean when you run into a problem. For builds that you'll deploy it's safest to always do a clean first to deal with any intricate dependencies that might not work otherwise.

That said, why in the world are you sharing source with a team through Dropbox? You should use Subversion or Git (or plenty of others) for source control management. They're designed for this and you're going to want them as soon as you deal with anything potentially complex like branching and merging. Consider using GitHub if you want to avoid setting much up.

Clean is generally superfluous if you are adding or changing existing classes. javac checks the timestamp of class files to keep them up to date.

It becomes essential if some classes have been deleted. If you don't clean up first, you end up with outdated class files sometimes causing dependency issues.

And no, performing a clean up is not a performance impact worth to mention compared to other tasks involved in the build/deployment process.

A clean is usually necessary to reduce the chances of errors due to renames and things may get left over. However, I don't recommend doing it in Ant itself.

If you are using git, use the exec task to execute the command

git clean -fdx .
git reset --hard HEAD

From the root of your project file. This will remove any files that are not part of source control and reset it to the top of the checked out state.

Otherwise I would do an cmd /c rd /s on Windows or rm -rf on UNIX on the build folders.

The javac commands documentation says :Only Java files that have no corresponding .class file or where the class file is older than the .java file will be compiled.

So there is no need to clean the resources every time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM