tags:

views:

60

answers:

1

I am using ant script for generating war file, it will generate the war file. please see the below script

<target name="war" depends="build">
  <mkdir dir="${dist}" /> 
  <jar destfile="${dist}/${proj_name}.war" basedir="${build}" />
</target>

If it generates a new war file, then i want to have a property to set the value as "newupdates" otherwise i want to know "noupdates"

A: 

A strategy to do this could be to use the UpToDate task to set the property. You just have to copy the war file to war.bak just after performing the uptodate check, to prepare for the next run.

Another strategy (probably even better) would be to use the UpToDate task to determine if the war has to be generated, setting a property, e.g myuptodateproperty. Then call your war generation target, and make sure it has an if=${myuptodateproperty} constraint, in order not to regenerate the war if it is not needed.

You can use something in the line of (untested code, may need some work):

<target name="war" depends="clean,fillbuildanddist,build">
  <mkdir dir="${dist}" />
  <uptodate targetfile="${dist}/${proj_name}.war" property="uptodatewar">
    <fileset dir="${build}" />
  </uptodate>
  <antcall target="makewar" />
</target>

<target name="makewar" unless="uptodatewar">
  <jar destfile="${dist}/${proj_name}.war" basedir="${build}" />
</target>

With this, the property uptodatewar should be set to true only if the war does not need to be rebuilt, and thus the jar task will only be called in this case. In targets that depend on the war target, you can use the uptodatewar to perform tasks only if the war is new.

tonio
This is gomathi, tonio, can you explain in detail, following is the code<target name="war" depends="clean,fillbuildanddist,build"> <mkdir dir="${dist}" /> <jar destfile="${dist}/${proj_name}.war" basedir="${build}" /> </target>Sometimes no war file is generated, if the war file in {dist} folder, is uptodate one. In that case i want to have property which should have "noupdates happened". Can you give any code snippet for my better understanding
gomathi
updated the answer with sample code
tonio