dynamically include zipfilesets into a WAR
Posted
by
Konstantin
on Stack Overflow
See other posts from Stack Overflow
or by Konstantin
Published on 2011-01-03T09:25:47Z
Indexed on
2011/01/04
22:53 UTC
Read the original article
Hit count: 287
hi all - a bit of clumsy situation but for the moment we cannot migrate to more straight-forward project layout.
We have a project called myServices and it has 2 source folders (yes, I know, but that's the way it is for now) - I'm trying to make build process a bit more flexible so we now have a property called artifact.names that will be parsed by generic build.xml and based on name, it will call either jar or war task, eg. myService-war will create a WAR file with the following zipfilesets included there: myService-war-classes, myService-war-web-inf, myService-war-meta-inf. I want to add a bit more flexibility, and allow having additional zipfilesets, eg. myService-war-etc-1,2 etc - so these will be picked up by the package target automatically. I cannot use "if" inside war target, and also ${ant.refid:myService-war-classes} property is not resolved, so I'm kind of stuck at the moment with my options - how do I dynamically include a zipfileset into a WAR? You can refer to fileset by id, but it MUST be defined then, eg. you can't have it optional on project level. Thank you. Some build.xml snippets:
<target name="archive">
<for list="${artifact.names}" param="artifact">
<sequential>
<echo>Packaging artifact @{artifact} of project ${project.name}</echo>
<property name="display.@{artifact}.packaging" refid="@{artifact}.packaging" />
<echo>${display.@{artifact}.packaging}</echo>
<propertyregex property="@{artifact}.archive.type"
input="@{artifact}"
regexp="([a-zA-Z0-9]*)(\-)([ejw]ar)"
select="\3"
casesensitive="false"/>
<propertyregex property="@{artifact}.base.name"
input="@{artifact}"
regexp="([a-zA-Z0-9]*)(\-)([ejw]ar)"
select="\1"
casesensitive="false"/>
<echo>${@{artifact}.archive.type}</echo>
<if>
<then>
<war destfile="${jar.dir}/${@{artifact}.base.name}.war"
compress="true" needxmlfile="false">
<resources refid="@{artifact}.packaging" />
<zipfileset refid="@{artifact}-classes" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-meta-inf" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-web-inf" erroronmissingdir="false" />
<!-- Additional zipfilesets to package -->
<zipfileset refid="@{artifact}-etc-2" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-3" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-4" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-5" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-6" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-7" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-8" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-9" erroronmissingdir="false" />
<zipfileset refid="@{artifact}-etc-10" erroronmissingdir="false" />
</war>
</then>
<!-- Generic JAR packaging -->
<else>
<jar destfile="${jar.dir}/@{artifact}.jar" compress="true">
<resources refid="@{artifact}.packaging" />
<zipfileset refid="@{artifact}-meta-inf" erroronmissingdir="false" />
</jar>
</else>
</if>
</sequential>
</for>
</target>
© Stack Overflow or respective owner