I seem to be getting run-time errors in my project when using javac fo开发者_如何学运维r incremental builds. Is this type of workflow supported? For example, if A.java
depends on B.java
, and B.java
is modified; will javac recompile A.java
because its dependency changed?
Right now I'm using a javac ant build-task for compiling:
<javac destdir="${classes.dir}"
srcdir="${src.dir}"
source="${javac.version}"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
includeantruntime="build.sysclasspath=last">
<classpath refid="compile.classpath" />
<classpath refid="junit.classpath" />
</javac>
Since you're using ant, check out the depend task.
The javac
command line compiler will compile every source file given on the command line, and additionally everything on which these depend, if they don't have newer class files.
The ant javac
task tries to be a bit smarter, to avoid compiling always everything - it recompiles only those files which have changed (i.e. are newer than their respective class files). This does not pay attention to the case that maybe the dependency of some class changed, and thus other classes need to be recompiled too.
In my current project, I simply do ant clean
whenever I have problems on tests (and of course before any production deployment), which deletes all class files. But as vanza said, there is the depend
task whose task is to find and delete all classes who depend on your changed classes - run this before your javac
task and you should be good.
It depends on what has changed in B.java. If nothing changed that affected how the class is presented to A, then javac doesn't need to recompile A.java for the changes to take effect.
That said, if you are seeing behavior where you believe old code is being loaded and run, I'd be more suspicious of the deployment/packaging process than the compilation process. YMMV.
精彩评论