Reputation: 31
How to dynamically add jars to javac classpath in ant ?
e.g.
the properties file should be (this list can change and include different jars in different directories): dyna.jars=../../dir1/api1.jar;../dir2/api2.jar
in build.xml
<javac
srcdir="${javac.srcdir}"
.....
>
<classpath refid="${dyna.jars}" />
</javac>
Thank you.
Upvotes: 3
Views: 9831
Reputation: 20371
I can't quite tell if dir1
and dir2
are going to be changing also or just the JARs in those directories but assuming those directories are going to be named the same, the following will include all JARs under dir
and dir2
and create a <path>
with id="dyna.jars"
. Note that it should be refid="dyna.jars"
and not refid="${dyna.jars}"
<path id="dyna.jars">
<fileset dir="../../dir1">
<include name="**/*.jar"/>
</fileset>
<fileset dir="../../dir2">
<include name="**/*.jar"/>
</fileset>
</path>
<javac srcdir="${javac.srcdir}" .....>
<classpath refid="dyna.jars" />
</javac>
Upvotes: 10