Question

We have an ant build process that currently build our war file. A subset of non compiled files (html) in the war have the need for token replacement however I don't want to do that on disk (we don't want to save the changes). Is there any way to perform the token replacement as the war is being built.

Current war process

<war basedir="${company.webapps.dir}" destfile="${dist.dir}/${company.war.filename}"
     webxml="${company.webapps.dir}/WEB-INF/web.xml" update="true">
    <exclude name="WEB-INF/**" />
    <exclude name="**/*.coffee" />
    <exclude name="**/*.haml" />
    <exclude name="**/*.sass" />
    <exclude name="**/*.scss" />
    <webinf dir="${company.webapps.dir}/WEB-INF/">
        <include name="**/*" />
        <exclude name="**/servlet-api.jar" />
    </webinf>
    <manifest>
      <attribute name="build-timestamp" value="${build.info.timestamp}" />
    </manifest>
</war>

If it didn't add a large amount of time I'd be ok with this being a post WAR task

Was it helpful?

Solution

I'm confused by your statement "I don't want to do that on the disk. (We don't want to save the changes.)". Can you elaborate on that. You can use the <copy/> task with <filterset> and that will allow you to process your HTML files and replace whatever tokens you want to replace in them.

Then you can use the copied versions of the files that have the replaced tokens in your war. I tried using <filterset> in the war itself, but it doesn't work with <fileset> or <classes>. You have to use <copy> to use <filterset>, and that's how I've always done it.

What do you mean save the changes? You don't have to save the copied files, they're work files just like everything else.

<copy dir="${html.dir}"
    todir="${html.work.dir}">
    <filterset>
       <filter token="${token1}" value="${value1}"/>
       <filter token="${token2}" value="${value2}"/>
    <filterset>
</copy>

<war destfile="${war.file}"
    webxml="${web.xml.file}">
    <classes dir="${html.work.dir}"/>   <!-- The munged HTML files -->

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top