Is it possible to determine that the content of a specific folder has changed, and when it happens, run an ANT task on demand?
In one of my projects the build time is too long. I was able to locate the dependencies, but every time I'm executing a build I have to perform a clean, which deletes all the java files and after that the javac recompiles everything. This consumes a lot of time.
I'm using ANT for build and I was thinking; is it possible to perform a clean (which deletes files) on demand? For the better understanding I made up an example:
- target top: builds the top.jar
- target first: builds the first.jar
- target second: builds the second.jar
top.jar depends on first.jar and second.jar. If I change any files associated to second.jar, ANT will run the second target, and when this affects the top.jar, then ANT will run the top target. So far so good.
But, it can happen that I rename a class in second.jar - with eclipse for example -, and I end up with two classes: the old class and the new class. Different names, but same content. This can be a problem, that's why I have to run the clean target all over the time.
In the example above, I have no problem with running the clean only for the target, which has changed.
So my question: is it possible to determine that the content of a specific folder has changed, and when it happens, run an ANT task on demand?
I looked around and there is an ANT task with almost the same functionality I need. It is called depend. Unfortunately it doesn'开发者_运维问答t perform a full delete.
Might libnotify bindings for java be helpful? If you don't need to run this within java, check out inotify, Kqueue, or the like.
Another possibility would be to switch to an IDE that automatically compiles everything for you in an intelligent way. For example Eclipse compiles every class when it is saved in the editor.
Additionally it is possible to define custom builders (e.g. an ant task) that are executed before or afterwards. That would allow you to automatically update your JAR files using the class files generated by Eclipse from the project's bin
directory.
There is the <depend>
task in Ant which may do what you want.
I might have found a solution to my problem. I'm going to use the outofdate task of ant contrib:
<outofdate>
<sourcefiles path="src3"/>
<targetfiles path="target/second.jar"/>
<sequential>
<delete includeemptydirs="true">
<fileset dir="bin3" includes="**/*"/>
</delete>
<delete file="target/second.jar"/>
</sequential>
</outofdate>
<javac .../>
精彩评论