Ant: adding multiple jars in classpath dynamically

How to dynamically add jars to javac class path in ant?

eg.

there should be a properties file (this list can be modified and contain different banks in different directories): dyna.jars = .. / .. / dir1 / api1.jar; ../ dir2 / api2.jar

in the build.xml file

            <javac
                srcdir="${javac.srcdir}"
                .....
            >
            <classpath refid="${dyna.jars}" />

            </javac>

Thank.

+3
source share
1 answer

I can not say for sure whether the change t20 and t21 as amended or JAR only in these directories, but on the condition that these directories will be called the same, the following will include all the JAR in the section dirand dir2and create <path>using id="dyna.jars". Please note that this should be refid="dyna.jars", notrefid="${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>
+9
source

All Articles