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:
D.Shawley
2010-09-01 13:10:31
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
2010-09-01 13:16:36
the the move then replace is working fine for me now no need to get as complicated as xslt
dstarh
2010-09-02 14:08:58
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
2010-09-01 13:17:14
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
2010-09-01 13:20:12
+1
A:
ended up just doing :
<replace file="${j2ee.build.dir}/${j2ee.app..name}/META-INF/application.xml" token="</application>" value="<module><web><web-uri>admin.war</web-uri><context-root>/admin</context-root></web></module></application>"/>
Rather hackish but couldn't come up with another way to edit the file easily
dstarh
2010-09-01 14:32:29