user766750
user766750

Reputation: 31

Ant : adding multiple jars in classpath dynamically

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

Answers (1)

no.good.at.coding
no.good.at.coding

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

Related Questions