read properties file inside ant taskdef

289 views Asked by At

I'm defining a build.xml file and I need to read some paths from a properties file. Reading from it is ok on my defined targets. The problem comes when I try to read the values inside my taskdef. How can I achieve this?

I have something like this:

<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
   <classpath>
      <fileset dir="${paths.jaxb.lib}" includes="*.jar" />
   </classpath>
</taskdef>

My "paths.jaxb.lib" is the path to the jaxb lib folder. How can I get this value from my paths.properties file?

1

There are 1 answers

0
Chad Nouis On BEST ANSWER

Read the properties file before the <taskdef> task.

If paths.properties is...

paths.jaxb.lib=path/to/my/jaxb/lib

...then in build.xml...

<!-- Loading the Java properties file sets the paths.jaxb.lib Ant property. -->
<property file="paths.properties"/>

<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
  <classpath>
    <fileset dir="${paths.jaxb.lib}" includes="*.jar" />
  </classpath>
</taskdef>