Ant:源文件和目标文件是一样的.如何检测变化? [英] Ant: Source and target files are the same. How to detect a change?

查看:24
本文介绍了Ant:源文件和目标文件是一样的.如何检测变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 JiBX.需要知道的重要一点是 JiBX 会修改已编译的类文件.

We are using JiBX. The important thing to know is that JiBX modifies the already compiled class files.

我们进行编译:

<javac destdir="${main.destdir}">
    <src path="${main.srcdir}"/>
    <classpath refid="main.classpath"/>
</javac>

然后,我们调用 JiBX:

Then, we call JiBX:

<jibx load="true"
    binding="{$binding.file}">
    <classpath refid="main.classpath"/>
    <classpath refid="main.destdir.classpath"/>
</jibx>

这使用一个 XML 文件来更新由上面的 编译的类文件.问题是我怎么知道文件已经编译,但没有被 JiBX 处理?我想在我的程序中加入一些逻辑,这样文件就不会被 JiBX 更新两次.此外,重复已经完成的工作是不好的形式.

This uses an XML file that updates the classfiles compiled by <javac> above. The problem is how do I know that the files have been compiled, but not processed by JiBX? I'd like to put some logic in my program, so that files are not updated twice by JiBX. Besides, it's bad form to duplicate work that already been done.

推荐答案

在jibx构建步骤之后,生成一个marker文件,例如

After the jibx build step, generate a marker file, e.g.

<touch file="${target.dir}/jibx.marker" />

仅当标记文件比 .class 文件旧时才执行 jibx 构建步骤(表明 javac 比上一个 jibx 运行得更近).

Only perform the jibx build step if that marker file is older than the .class files (indicating that the javac ran more recently than the last jibx).

对于那一点逻辑,你可以使用传统的蚂蚁方式:

For that bit of logic, you can use the traditional ant way:

<uptodate property="jibx.uptodate" targetfile="${target.dir}/jibx.marker">
   <srcfiles dir="${main.destdir}" includes="...../*.class" />
</uptodate>

然后在调用 jixb 目标时使用带有unless 子句的属性.

And then use the property with an unless clause when invoking the jixb target.

或者,您可以使用 Antcontrib 的过时替代方案:

Or, you can use Antcontrib's outofdate alternative:

<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>

这篇关于Ant:源文件和目标文件是一样的.如何检测变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆