ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brent <>
Subject taskdef parsed before properties expansion if use property files?
Date Thu, 24 Jul 2008 20:18:21 GMT
I need to use JAXB to autogenerate java source files from an xml schema.  The canonical way
to do this in ant, judging from a recent websearch, is the following fragment that you need
to put in your build file:
    <taskdef name="xjc" classname="">
            <fileset dir="[jaxws-ri HOME]/lib" includes="*.jar"/>
    <target name="generateSrcJaxb" depends="_cleanSrcJaxb">
            <arg value="-npa"/>    <!-- suppress generation of package level annotations
            <schema file="${dirConfig}/mySchema.xsd"/>

I need the <classpath> element inside the <taskdef> because my employer is still
stuck on jdk 1.5 (I understand that 1.6 has this stuff all builtin).

The code above works perfectly if I use a hardcoded path (either absolute or relative) for
[jaxws-ri HOME].  This, of course, is uncool, because I need the build file to work on other
machines besides my own.

The obvious solution is to not hardcode the paths but use properties.  I have done this in
the past, and it always worked perfectly for all of my normal ant targets.  For the problem
at hand, the code that I would LIKE to use inside the <classpath> element above is simply
            <fileset dir="${dirRoot}/ThirdParty/jaxws-ri/lib" includes="*.jar"/>

This code actually works, but only if I define the dirRoot property on the command line. 
That is, if I invoke the build using something like
    ant -DdirRoot=../ generateSrcJaxb

This is annoying: i have already defined the dirRoot properties (plus several others) in an
external file called  I want to invoke the build using
    ant  -propertyfile ./  generateSrcJaxb

Unfortunately, when i try executing the code above, I get this error:
    C:\...\build.xml:155: C:...\${dirRoot}\ThirdParty\jaxws-ri\lib not found.
(where ... suppress some long and irrelevant paths).

I get the same error if I invoke the build using
    ant  generateSrcJaxb
but place the code
    <property file="./"/>
inside my build file before the other stuff above.

What seems to be happening is this:
1) ant reads any -D properties from the command line
2) it parses the build.xml file
3) it then reads in any properties from external property files (as specified by either -propertyfile
on the command line or <property file="..."/> elements)
4) it finally executes the build file

The code that I want to use
    ant  -propertyfile ./  generateSrcJaxb
fails here apparently because ant thinks that it needs to know the value of the dirRoot property
inside the <taskdef> during parse time instead of at execution time, unlike every other
element of the build file, and this info is not available because it does not parse
early enough, like it ought to.

Is this a correct diagnosis of what is going on?

Any workarounds?

Should I file a bug report?

Note: I am using the latest prd release, ant 1.7.1 (behavior also present in 1.7.0).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message