Is there an ant task to add a .war to an existing exploded ear
Have a build process that 开发者_如何学JAVAcan'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?
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
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>
Won't<copy>
do the job?- What about using
<xslt>
to modifyapplication.xml
then?
精彩评论