tags:

views:

34

answers:

3

Have a build process that can't be edited and need to pack another war in the the ear that is generated. The ear is exploded so it's just a matter of copying the war file into it but the application.xml needs to be updated so I'd like to find an ant task that will do this. Anyone know of one that will work?

A: 
  1. Won't <copy> do the job?
  2. What about using <xslt> to modify application.xml then?
D.Shawley
no because you have to update application.xml to put the module block in it or the war won't deploy<module><web><web-uri>admin.war</web-uri><context-root>/admin</context-root></web></module>
dstarh
the the move then replace is working fine for me now no need to get as complicated as xslt
dstarh
A: 

The idea is to create the war and put the file into the ear directory, see the following build.xml code

<?xml version="1.0"?>
<project name="Add war to ear example" default="all" basedir=".">

<target name="init">
<property name="root.directory" value="${basedir}"/>
<property name="classdir" value="${root.directory}/build/src"/>
<property name="src" value="${root.directory}/src"/>
<property name="web" value="${root.directory}/web"/>
<property name="deploymentdescription" value="${root.directory}/build/deploymentdescriptors"/>

<property name="war.file" value="test.war"/>
<property name="ear.file" value="test.ear"/>

<property name="ear.directory" value="${root.directory}/build/ear"/>
<property name="war.directory" value="${root.directory}/build/war"/>

<!-- Create Web-inf and classes directories -->
<mkdir dir="${war.directory}/WEB-INF"/>
<mkdir dir="${war.directory}/WEB-INF/classes"/>

<!-- Create Meta-inf and classes directories -->
<mkdir dir="${ear.directory}/META-INF"/>

</target>

<!-- Main target -->
<target name="all" depends="init,build,buildWar,buildEar"/>

<!-- Compile Java Files and store in /build/src directory -->
<target name="build" >
<javac srcdir="${src}" destdir="${classdir}" debug="true" includes="**/*.java" />
</target>

<!-- Create the War File -->
<target name="buildWar" depends="init">
<copy todir="${war.directory}/WEB-INF/classes">
<fileset dir="${classdir}" includes="**/*.class" /> 
</copy>

<copy todir="${war.directory}/WEB-INF">
<fileset dir="${deploymentdescription}" includes="web.xml" /> 
</copy>

<copy todir="${war.directory}">
<fileset dir="${web}" includes="**/*.*" /> 
</copy>

<!-- Create war file and place in ear directory -->
<jar jarfile="${ear.directory}/${war.file}" basedir="${war.directory}" />
</target>

<!-- Create the War File -->
<target name="buildEar" depends="init">
<copy todir="${ear.directory}/META-INF">
<fileset dir="${deploymentdescription}" includes="application.xml" /> 
</copy>

<!-- Create ear file and place in ear directory -->
<jar jarfile="${root.directory}/${ear.file}" basedir="${ear.directory}" />
</target>

</project>
mrjohn
i already have something that builds my ear, already have my war task, what I don't have is the task that updates the ear's application.xml with the new war
dstarh
+1  A: 

ended up just doing :

<replace file="${j2ee.build.dir}/${j2ee.app..name}/META-INF/application.xml" token="&lt;/application&gt;" value="&lt;module&gt;&lt;web&gt;&lt;web-uri&gt;admin.war&lt;/web-uri&gt;&lt;context-root&gt;/admin&lt;/context-root&gt;&lt;/web&gt;&lt;/module&gt;&lt;/application&gt;"/>

Rather hackish but couldn't come up with another way to edit the file easily

dstarh