Ant: how to force compile java compilation in case java files were changed but sources are not


I have the following information:
I have a java project (myProj) that uses common.jar from another (shared) project. I want the javac ant task to work even if myProj sources have not changed , if the common.jar file has changed (since myProj sources depend on it and may be invalid now). <i> I have a task that copies common.jar from a central location in myProj lib if it has been modified, and I can use it to set the property to force to compile, to get it over with. I do not know how (or if) I can say that the javac task is to try to compile? I do not want to change myProj sources (or timestamps) to get started.
Excerpt from ant build.xml file:

<path id="project.class.path"> <pathelement location... /> ... <fileset dir="lib" includes="**/*.jar" /> </path> <target name="copyLibs" > <copy file="${central.loc}/common.jar" todir="lib" /> ... </target> <target name="javac" > <javac srcdir="src" includes="**" excludes=... > <classpath refid="project.class.path"/> </javac> </target> 

Thanks in advance,
Ephaya

+4
source share
1 answer

Use the delete task before javac to clean up old compiled classes:

In general, Java classes should not be recompiled unless the API of the dependent classes has changed.

I would also suggest using maven, as it handles dependencies more competently.

+2
source

Source: https://habr.com/ru/post/1333383/


All Articles