You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jay Glanville <di...@nortelnetworks.com> on 2000/08/10 16:15:03 UTC
What is the best way to set up a class path variable?
Basically, my project has two or three targets that have a common classpath.
What is the best way to set up a property/variable so that it's common to
all?
I've thought of one or two:
- statically create a property outside of all targets. e.g.: <property
name="my.classpath" value="path/one;path/two;...;path/ten" />
- statically create the property inside of a common target. e.g.:
<target name="initialize">
<property name="my.classpath" value="path/one;path/two;...;path/ten" />
</target>
and have all targets call this one (e.g.: <target name="main"
depends="initialize">)
Is there other ways to do this (other then setting up properties from
resources or files)? Which is the best way to do this?
----------------------------------------------------------------------------
-----
Jay Dickon Glanville
P066 - SiteManager Development
613-765-1144 (ESN 395-1144)
MS: 045/55/A05
E-Mail: dickon@nortelnetworks.com
Re: What is the best way to set up a class path variable?
Posted by Stefan Bodewig <bo...@bost.de>.
Both your solutions (using a <property> outside of <target> or in a
common <target>) will work - or not.
<property> is always global - nest it into a <target>, it will still
be global and visible to all tasks. Even worse, only the very first
<property> for a given name is ever considered, all others are
silently ignored - so you can't have two different values in different
targets (at least not without spawning another <ant> task to process
the file again).
Given that, I'd go with the global <property> way, as it doesn't even
look as if the <property> was set at runtime.
And to show you a way that doesn't work with Ant 1.1 but will be
possible in the next release:
<task1>
<classpath ID="my.classpath">
<pathelement location="path/one" />
<pathelement location="path/two" />
...
<pathelement location="path/ten" />
</classpath>
</task1>
<task2>
<classpathref refid="my.classpath" />
</task2>
...
Stefan