How to add to classpath all classes from set of directories in ant?
ant
Solution
You can set up a path to include all .class files from your specific directories:
<path id="mypath">
<fileset dir="${root.dir}">
<include name="lib1dir/**/*.class lib2dir/**/*.class lib3dir/**/*.class"/>
</fileset>
</path>
However, if you want to use this path as a classpath, you only need to reference the root folders, otherwise you will get `ClassNotFoundError`s as the package names translate into directories:
<path id="build.classpath">
<dirset dir="${root.dir}">
<include name="lib1dir lib2dir lib3dir"/>
</dirset>
</path>
Then reference the path by its id when using (e.g. for classpath):
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
Problem
How to add to classpath all classes from set of directories? I have following property: class.dirs=lib1dir,lib2dir,lib3dir There are classes under these directories. Is it possible to add all classes under these directories to classpath? Something like: ``` <classpath> <dirset dir="${root.dir}" includes="${class.dirs}/**/*.class"/> </classpath> ``` or ``` <classpath> <pathelement location="${class.dirs}" /> </classpath> ``` But this example does not work, of course.