Hello,
I have an ant script that I run during "install" for a project which
essentially unjars the created WAR file, extracting out *.xml and *.properties
files and doing a mass replacement for various tokens and then updates the WAR
file with the modified files. This ant script invokes other ant scripts, one
of which is the "Tokenize.xml" script I wrote which unjars the desired files,
does the token replacement, and then updates the WAR file. When I run this
script directly from the command line (i.e., ant -buildfile=...) it works every
time. When I invoke this same script from Maven2 using the AntRun plugin, it
works the first time and from then on until something "magical" happens
everything works except the updating of the jar file.
The Tokenize.xml file is listed below. It simply unjars three types of files
out of whatever JAR (or WAR) file it is given into a specified working
directory. Then it does token replacement on the files in that working
directory. Then it simply updates the original JAR file with any modified
files. Not very complicated. If I run this set of scripts from Maven2, it
works once, then if I rebuild immediately the jar update fails. If I wait ten
or fifteen minutes and then run again, it often will work. I have not figured
out how to turn on the verbose ant option from within AntRun, so I can't get to
any meaningful diagnostic output. I have run in the verbose mode from ant, but
of course the script always works within ant!
If anyone has any ideas, I would be appreciative.
Thanks!
Walt Barrow
<?xml version="1.0"?>
<!DOCTYPE project>
<!--
Tokenize.xml
Description: Tokenize an archive file (e.g., war, jar, sar).
Targets: tokenizeFile, tokenizeDir
-->
<project name="ArchitectureProject" default="" basedir=".">
<!-- Read all the environment variables into env.xxx type properties -->
<property environment="env"/>
<property name="m.default.replace.filter.file"
value="./DefaultReplaceFilter.xml" />
<!-- =================================================
TARGET: tokenizeFile (main target)
DESC: Perform token substitution on the contents of a jar.
1. unjar to temporary folder
2. replacing tokens
3. jar that temporary folder into single *.jar file
PARAMS: jar.path - path to jar file to tokenize, in place
working.dir - temporary directory to use
replace.filter.file (set to "NONE" if not used)
======================================================-->
<target name="tokenizeFile">
<echo message="****************************************" />
<echo message="jar.path is ${jar.path}" />
<echo message="working.dir is ${working.dir}" />
<condition property="m.do.other">
<not>
<equals arg1="${replace.filter.file}" arg2="NONE" />
</not>
</condition>
<!-- unjar files into the temporary directory -->
<antcall target="unjar">
<param name="p.jar.path" value="${jar.path}"/>
<param name="p.dest.dir" value="${working.dir}"/>
</antcall>
<!-- replacing tokens -->
<antcall target="defaultReplaceToken">
<param name="p.working.dir" value="${working.dir}"/>
</antcall>
<antcall target="replaceToken">
<param name="p.working.dir" value="${working.dir}"/>
</antcall>
<!-- jar folder/files -->
<antcall target="jar">
<param name="p.src.dir" value="${working.dir}"/>
<param name="p.jar.path" value="${jar.path}"/>
</antcall>
<!-- delete the temp folder -->
<!--
<delete dir="${working.dir}"/>
-->
</target>
<!-- =================================================
TARGET: tokenizeDir (main target)
DESC: Perform token substitution on a specified directory.
PARAMS: working.dir
replace.filter.file (set to "NONE" if not used)
======================================================-->
<target name="tokenizeDir">
<echo message="****************************************" />
<echo message="working.dir is ${working.dir}" />
<condition property="m.do.other">
<not>
<equals arg1="${replace.filter.file}" arg2="NONE" />
</not>
</condition>
<!-- replacing tokens -->
<antcall target="defaultReplaceToken">
<param name="p.working.dir" value="${working.dir}"/>
</antcall>
<antcall target="replaceToken">
<param name="p.working.dir" value="${working.dir}"/>
</antcall>
</target>
<!-- =================================================
TARGET: unjar
DESC: unjar filepathname - file to unjar
PARAMS: p.jar.path - source file path
p.dest.dir - destination directory
======================================================-->
<target name="unjar">
<!-- delete the temp folder -->
<delete dir="${p.dest.dir}"/>
<!-- create temporary folder for unjar -->
<mkdir dir="${p.dest.dir}"/>
<unjar src="${p.jar.path}" dest="${p.dest.dir}" >
<patternset>
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.txt" />
</patternset>
</unjar>
</target>
<!-- =================================================
TARGET: defaultReplaceToken and replacetoken
DESC: Replacing tokens
PARAMS: p.working.dir - working directory
======================================================-->
<target name="defaultReplaceToken">
<echo message="Invoking ${m.default.replace.filter.file}" />
<ant antfile="${m.default.replace.filter.file}" target="replacetoken"
inheritAll="true" >
<property name="working.dir" value="${p.working.dir}" />
</ant>
</target>
<target name="replaceToken" if="m.do.other">
<echo message="Invoking ${replace.filter.file}" />
<ant antfile="${replace.filter.file}" target="replacetoken"
inheritAll="true" >
<property name="working.dir" value="${p.working.dir}" />
</ant>
</target>
<!-- =================================================
TARGET: jar
DESC: Jar all the files in the src.dir
PARAMS: p.jar.path - target file name
p.src.dir - destination directory
======================================================-->
<target name="jar">
<!-- <delete file="${p.jar.path}" />
-->
<jar destfile="${p.jar.path}"
basedir="${p.src.dir}"
includes="**/*.xml, **/*.properties, **/*.txt"
update="true"/>
</target>
</project>