简体   繁体   中英

ANT target doesn't overwrite the existing the xml file

I am working on one ant script and my ant target unzips the war file and then rename/replace the file and zip the war file again. So the structure of my war file is having WEB-INF folder which is having web-muqmreports.xml and web.xml file.

My target unzips the war file and then makes a copy of web-muqmreports.xml with the name web.xml, and puts it back into the war file, then zips it, but the issue is I have already one web.xml file in WEB-INF folder, so when the target puts the renamed web.xml file inside the WEB-INF folder, it doesn't overwrite the existing web.xml file.

My target is working fine. I checked it with not renaming the file name with web.xml. I renamed it with web_tt.xml and after that I can see the file inside the war.

Can someone tell me why it is not overwriting the existing web.xml file?

Is there any way we can delete the existing web.xml file before the zip in the below target?

 <target name="env.replace.webxml">
        <echo message="Replacing app web.xml"/>
        <move todir="${deploy.war.dir}">
            <fileset dir="${deploy.war.dir}" includes="*.war" />
            <regexpmapper from=".*\.war" to="${deploy.appname}.war" />
        </move>
        <delete dir="WEB-INF"/>
        <unzip src="${deploy.war.dir}/${deploy.appname}.war" dest=".">
            <patternset>
                <include name="WEB-INF/${deploy.use.web.xml}"/>
            </patternset>
            <globmapper from="WEB-INF/${deploy.use.web.xml}" to="WEB-INF/web.xml"/>
        </unzip>
        <zip destfile="${deploy.war.dir}/${deploy.appname}.war" basedir="." includes="WEB-INF/web.xml" update="true"/>
 </target>

I fixed the issue I added one more step in my ant target

  <target name="env.replace.webxml">
        <echo message="Replacing app web.xml"/>
        <move todir="${deploy.war.dir}">
            <fileset dir="${deploy.war.dir}" includes="*.war" />
            <regexpmapper from=".*\.war" to="${deploy.appname}.war" />
        </move>
        <delete dir="WEB-INF"/>
        <unzip src="${deploy.war.dir}/${deploy.appname}.war" dest=".">
            <patternset>
                <include name="WEB-INF/${deploy.use.web.xml}"/>
            </patternset>
            <globmapper from="WEB-INF/${deploy.use.web.xml}" to="WEB-INF/web.xml"/>
        </unzip>
       **<tstamp> <format property="touch.time" pattern="MM/dd/yyyy hh:mm aa"/>  </tstamp>
       <touch datetime="${touch.time}">
        <fileset dir="." />
       </touch>**
        <zip destfile="${deploy.war.dir}/${deploy.appname}.war" basedir="." includes="WEB-INF/web.xml" update="true"/>
    </target>

I have similar issue. I had custom files including web.xml which I need to update in already builded war. What was crucial is to touch files from folder which I want to put inside war. Example below:

<target>
    <tstamp>
        <format property="touch.time" pattern="MM/dd/yyyy hh:mm:ss"/>
    </tstamp>
    <touch datetime="${touch.time}" pattern="MM/dd/yyyy hh:mm:ss">
        <fileset dir="${project.build.directory}/${war-update-dir}" />
    </touch>
    <war destfile="${final.war}" update="true" needxmlfile="false">
        <zipfileset dir="${project.build.directory}/${war-update-dir}" prefix=""/>
    </war>
    <delete dir="${project.build.directory}/${war-update-dir}"/>
</target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM