Paul Croarkin
Paul Croarkin

Reputation: 14675

How to correctly set an ant path id?

Given build.xml:

<project name="testant" default="main">
    <property name="local.builds.dir"  value="C:/scratch/${ant.project.name}"/>

    <target name="main">
        <echo>local.builds.dir = ${local.builds.dir}</echo>

        <path id="classpath.test">
            <pathelement location="${local.builds.dir}"/>
        </path>

        <echo>classpath.test = ${classpath.test}</echo>
    </target>
</project>

I would expect the output to be:

main:

[echo] local.builds.dir = C:/scratch/testant

[echo] classpath.test = C:/scratch/testant

BUILD SUCCESSFUL

but it is:

main:

[echo] local.builds.dir = C:/scratch/testant

[echo] classpath.test = ${classpath.test}

BUILD SUCCESSFUL

How do you correctly set 'classpath.test' in this case?

Upvotes: 1

Views: 6414

Answers (2)

charlie
charlie

Reputation: 1527

Easy way:

<echo>classpath.test = ${toString:classpath.test}</echo>

Upvotes: 1

Victor Sorokin
Victor Sorokin

Reputation: 12006

Use this version:

<project name="testant" default="main">
    <property name="local.builds.dir" value="C:/scratch/${ant.project.name}"/>

    <target name="main">
        <echo>local.builds.dir = ${local.builds.dir}</echo>

        <path id="classpath.test">
            <pathelement location="${local.builds.dir}"/>
        </path>

        <property name="d" refid="classpath.test"/>
        <echo>classpath.test = ${d}</echo>
    </target>
</project>

Upvotes: 2

Related Questions