--- Scott Ellsworth <[EMAIL PROTECTED]> wrote:
> I want to combine several jars during a build to make an output jar,
> and the list is set via a property. There are two good ways to do this
> that I know of:
>
> 1. Supply a zipfileset to the jar task
> 2. Supply src attribute to the unjar task, and do this once per file.
>
> I would prefer to supply the list of jars to be bundled as one comma or
> space separated list, as then it could be set in a single property.
>
> Regrettably, some targets need no zip files, some need one, and others
> need up to twelve zips bundled together, and so a fixed set of
> properties is clunky and prone to breakage, which is why I would rather
> use a single list of arbitrary length. Further, jar will not ignore a
> zipfileset with an empty src, so if I use a zipfileset, there must be a
> zip at the other end.
>
> I would love to write:
>
> <target name="jar" >
> <jar
> jarfile="${jar.dist}/${jar.baseName}-${DSTAMP}.jar"
> basedir="${compile.classes}">
> <zipfileset source="jar.extra.listofzips">
> </jar>
> </target>
>
> where
>
> jar.extra.listofzips="first.jar,second.jar"
>
> but if jar.extra.listofzips is blank, this throws an error, and if it
> has more than one member, I need it as a set of properties.
Well, it may have been the wine I had at lunch, but... this is the weird
way I came up with to do it:
1. Create (and source-control, of course :) a partial buildfile
template (say, buildjar.tmpl):
<project default="mkjar">
<target name="mkjar" >
<jar jarfile="${jar.dist}/${jar.baseName}-${DSTAMP}.jar"
basedir="${compile.classes}">
2. Have your <jar> target copy the template-file to buildjar.xml,
and use <script> to determine what, if any, <zipfileset>'s to
add, close off the <jar> task, <target>, and <project>, then
execute buildjar.xml via <ant>:
<target name="jar">
<copy file="buildjar.tmpl" tofile="buildjar.xml" overwrite="true"/>
<script language="javascript"> <![CDATA[
importClass(java.io.File);
importClass(java.io.FileWriter);
importClass(java.util.StringTokenizer);
buildfile = new File("buildjar.xml");
var append = true;
out = new FileWriter(buildfile, append);
zips = projname.getProperty("extra.zips");
if( zips ) {
st = new StringTokenizer(zips, " ,");
while (st.hasMoreTokens()) {
zipfile = st.nextToken();
out.write(" <zipfileset src=\"" + zipfile + "\"/>\n");
}
}
out.write(" </jar>\n");
out.write(" </target>\n");
out.write("</project>\n");
out.close();
]]> </script>
<ant antfile="buildjar.xml"/>
</target>
Given 'ant -Dextra.zips="one.jar two.jar" jar', you'll end up with
buildjar.xml being:
<project default="jar">
<target name="jar" >
<jar jarfile="${jar.dist}/${jar.baseName}-${DSTAMP}.jar"
basedir="${compile.classes}">
<zipfileset src="one.jar"/>
<zipfileset src="two.jar"/>
</jar>
</target>
</project>
Diane
=====
([EMAIL PROTECTED])
__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>