我们正在使用的JiBX 。 要知道,重要的是,JiBX的修改已编译的类文件。
我们做我们的编译:
<javac destdir="${main.destdir}">
<src path="${main.srcdir}"/>
<classpath refid="main.classpath"/>
</javac>
然后,我们调用了JiBX:
<jibx load="true"
binding="{$binding.file}">
<classpath refid="main.classpath"/>
<classpath refid="main.destdir.classpath"/>
</jibx>
此使用该更新由编译类文件的XML文件<javac>
上方。 问题是我怎么知道该文件已被编译,而不是由JiBX的处理? 我想放一些逻辑在我的程序,使通过的JiBX不更新两次文件。 此外,它的坏的形式复制的是已经完成的工作。
在JiBX的构建步骤后,生成一个标记文件,如
<touch file="${target.dir}/jibx.marker" />
只有当该标记文件比.class文件(表明是javac比上次的JiBX最近跑)较旧的执行JiBX的构建步骤。
对于逻辑的那一点,你可以使用传统的蚂蚁方式:
<uptodate property="jibx.uptodate" targetfile="${target.dir}/jibx.marker">
<srcfiles dir="${main.destdir}" includes="...../*.class" />
</uptodate>
然后使用属性与除非条款调用jixb目标时。
或者,你可以使用Antcontrib的outofdate选择:
<outofdate>
<sourcefiles>
<fileset dir="${main.destdir}" includes="...../*.class" />
</sourcefiles>
<targetfiles>
<fileset dir="${target.dir}" includes="jibx.marker"/>
</targetfiles>
<sequential>
<jibx load="true"
binding="{$binding.file}">
<classpath refid="main.classpath"/>
<classpath refid="main.destdir.classpath"/>
</jibx>
</sequential>
</outofdate>
我给这帕特里斯·M.因为他的建议让我在正确的轨道上。 但是,它并没有完全制定出如他说。 (对不起,如果我得到他代词错,但帕特里斯既可以是男性或女性的名字。)
我所要做的就是创建两个表文件:一个用于Java编译,以及一个用于JiBX的变化。
<!-- Check if Javac is out of date. If so, create javac watcher -->
<outofdate verbose="true">
<sourcefiles>
<fileset dir="${main.srcdir}">
<include name="*.java"/>
</fileset>
</sourcefiles>
<mapper type="regexp"
from="${main.srcdir}/(.*)\.java"
to="${main.destdir}/(\1).class"/>
<sequential>
<echo message="Java compiled"/>
<echo message="Java compiled"
file="${target.dir}/${javac.monitor.file}"/>
</sequential>
</outofdate>
<javac destdir="${main.destdir}"
debug="${javac.debug}">
<src path="${main.srcdir}"/>
<classpath refid="main.classpath"/>
</javac>
<!-- Compare javac and jibx monitoring file -->
<!-- If out of date, rerun jibx -->
<outofdate>
<sourcefiles>
<fileset dir="${target.dir}">
<include name="${javac.monitor.file}"/>
</fileset>
</sourcefiles>
<targetfiles>
<fileset dir="${target.dir}">
<include name="${jibx.monitor.file}"/>
</fileset>
</targetfiles>
<sequential>
<jibx load="true"
binding="${target.dir}/binding-gg.xml">
<classpath refid="main.classpath"/>
<classpath refid="main.destdir.classpath"/>
</jibx>
<!-- Create JiBX monitoring file -->
<echo message="Compiled and JiBX"
file="${target.dir}/${jibx.monitor.file}"/>
</sequential>
</outofdate>
我创建了javac的监控文件,如果源是过时与类的,因为当我编译的。 我有,当我运行的JiBX只创建了JiBX outofdate监测文件,这里面的<outofdate>
的JiBX的。
我想我也可以把源上的XML文件的JiBX也只是可以肯定的。
文章来源: Ant: Source and target files are the same. How to detect a change?