开发者

Is there an ant task to add a .war to an existing exploded ear

开发者 https://www.devze.com 2023-01-14 15:54 出处:网络
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

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="&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


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>


  1. Won't <copy> do the job?
  2. What about using <xslt> to modify application.xml then?
0

精彩评论

暂无评论...
验证码 换一张
取 消