You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Brent <yh...@yahoo.com> on 2008/07/24 22:18:21 UTC

taskdef parsed before properties expansion if use property files?

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="com.sun.tools.xjc.XJCTask">
        <classpath>
            <fileset dir="[jaxws-ri HOME]/lib" includes="*.jar"/>
        </classpath>
    </taskdef>
    
    <target name="generateSrcJaxb" depends="_cleanSrcJaxb">
        <xjc
            destdir="${dirSrc}"
            package="com.foo.bar"
        >
            <arg value="-npa"/>    <!-- suppress generation of package level annotations -->
            <schema file="${dirConfig}/mySchema.xsd"/>
        </xjc>
    </target>

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 build.properties.  I want to invoke the build using
    ant  -propertyfile ./build.properties  generateSrcJaxb

Unfortunately, when i try executing the code above, I get this error:
    BUILD FAILED
    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="./build.properties"/>
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 ./build.properties  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 build.properties 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: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: ant exec task trouble parsing quotes

Posted by Harnack Frank <Fr...@bitmarck.de>.
Hello,

you should try the java-Task.


Regards

Frank

-----Original Message-----
From: Ben Tu [mailto:btu@adobe.com] 
Sent: Tuesday, December 23, 2008 1:43 AM
To: Ant Users List
Subject: ant exec task trouble parsing quotes

Hi,
I am trying to run a java command using exec task in ant.
I ran into the error because one of the java command argument has space
between.
Any idea? Please help.
Thanks, 

Here is my ant task in build.xml file:
			    <exec dir="${temp-dir}"
executable="${java}">
					<arg value="-jar"/>
					<arg
value="${tools-dir}/test.jar" />			
					<arg value="-libraryjars"/>
					<arg
value="${env.JAVA_HOME}/jre/lib /rt.jar"/>
					<arg
value="-dontusemixedcaseclassnames"/>
					<arg
value="-renamesourcefileattribute"/>
					<arg value="SourceFile"/>
					<arg value="-keepattributes"/>
					<arg
value="SourceFile,LineNumberTable"/>
					<arg
value="@../../../built/temp.pro"/>
					<arg value="-injars"/>
					<arg
value="../../../built/classes"/>
					<arg value="-outjars"/>
					<arg
value="../../..built/temp"/>
					<arg value="-printmapping"/>
					<arg
value="../../../built/teting.txt"/>
				</exec>

Here is an output:

     [exec] Current OS is Windows XP
     [exec] Executing 'C:\Program Files\Java\jdk1.6.0_10\bin\java' with
arguments:
     [exec] '-jar'
     [exec] '../../../Tools/test.jar'
     [exec] '-libraryjars'
     [exec] 'C:\Program Files\Java\jdk1.6.0_10\jre\lib\rt.jar'
     [exec] '-dontusemixedcaseclassnames'
     [exec] '-renamesourcefileattribute'
     [exec] 'SourceFile'
     [exec] '-keepattributes'
     [exec] 'SourceFile,LineNumberTable'
     [exec] '@../../../built/temp/temp.pro'
     [exec] '-injars'
     [exec] '../../../built/temp/classes'
     [exec] '-outjars'
     [exec] '../../../built/temp/'
     [exec] '-printmapping'
     [exec] '../../../built/teting.txt'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
     [exec] Error: Expecting class path separator ';' before
'Files\Java\jdk1.6.0_10\jre\lib\rt.jar' in argument number 2
     [exec] Result: 1

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


ant exec task trouble parsing quotes

Posted by Ben Tu <bt...@adobe.com>.
Hi,
I am trying to run a java command using exec task in ant.
I ran into the error because one of the java command argument has space between.
Any idea? Please help.
Thanks, 

Here is my ant task in build.xml file:
			    <exec dir="${temp-dir}" executable="${java}">
					<arg value="-jar"/>
					<arg value="${tools-dir}/test.jar" />			
					<arg value="-libraryjars"/>
					<arg value="${env.JAVA_HOME}/jre/lib /rt.jar"/>
					<arg value="-dontusemixedcaseclassnames"/>
					<arg value="-renamesourcefileattribute"/>
					<arg value="SourceFile"/>
					<arg value="-keepattributes"/>
					<arg value="SourceFile,LineNumberTable"/>
					<arg value="@../../../built/temp.pro"/>
					<arg value="-injars"/>
					<arg value="../../../built/classes"/>
					<arg value="-outjars"/>
					<arg value="../../..built/temp"/>
					<arg value="-printmapping"/>
					<arg value="../../../built/teting.txt"/>
				</exec>

Here is an output:

     [exec] Current OS is Windows XP
     [exec] Executing 'C:\Program Files\Java\jdk1.6.0_10\bin\java' with arguments:
     [exec] '-jar'
     [exec] '../../../Tools/test.jar'
     [exec] '-libraryjars'
     [exec] 'C:\Program Files\Java\jdk1.6.0_10\jre\lib\rt.jar'
     [exec] '-dontusemixedcaseclassnames'
     [exec] '-renamesourcefileattribute'
     [exec] 'SourceFile'
     [exec] '-keepattributes'
     [exec] 'SourceFile,LineNumberTable'
     [exec] '@../../../built/temp/temp.pro'
     [exec] '-injars'
     [exec] '../../../built/temp/classes'
     [exec] '-outjars'
     [exec] '../../../built/temp/'
     [exec] '-printmapping'
     [exec] '../../../built/teting.txt'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
     [exec] Error: Expecting class path separator ';' before 'Files\Java\jdk1.6.0_10\jre\lib\rt.jar' in argument number 2
     [exec] Result: 1

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org