Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add to classpath all classes from set of directories in ant?

Tags:

ant

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.

like image 966
Volodymyr Bezuglyy Avatar asked May 22 '12 14:05

Volodymyr Bezuglyy


1 Answers

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 ClassNotFoundErrors 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" />
like image 177
Attila Avatar answered Nov 15 '22 16:11

Attila