tags:

views:

127

answers:

0

I'm writing an Ant macrodef in an antlib file to be distributed in a Jar. As part of that macrodef, I'm copying the contents of one file to a temporary file and doing some filtering during the copy (replacing tokens and such).

Now, this is all good and fine if the macrodef is referencing the file to copy on the file system. However, this means either that template file needs to be distributed alongside the Jar and put into the correct location by users and/or a property needs exposed on the macrodef to specify where this template lives.

Ideally, I could just include this file in the Jar with the macrodef and the macrodef could reference it. For instance, if my Jar looks like:

  • macros.jar/
    • /com
      • /foo
        • antlib.xml
    • Template.txt

my macrodef would be along the lines of:

...

And the usage in the build file would be similar to:

<?xml version="1.0" encoding="UTF-8"?>
<project name="createDocumentClass" default="build">
    <taskdef resource="com/foo/antlib.xml" classpath="./lib/macros.jar" />

    <target name="build">
        <createDocumentClass />
    </target>

</project>

I know I can get at the file via a zipfileset, but that implies I point at the Jar file somewhere other than in the taskdef in the build file, which I'd like to avoid (unless there's some way to specify this in the macrodef in a generic fashion, of course).

Note that I'm using Ant 1.8. Any help would be greatly appreciated!