如何将ant中一组目录中的所有类添加到类路径中? [英] How to add to classpath all classes from set of directories in ant?
问题描述
如何将目录集中的所有类添加到类路径?
How to add to classpath all classes from set of directories?
我有以下属性:
class.dirs=lib1dir,lib2dir,lib3dir
class.dirs=lib1dir,lib2dir,lib3dir
这些目录下有类.
是否可以将这些目录下的所有类添加到类路径?
There are classes under these directories.
Is it possible to add all classes under these directories to classpath?
类似于:
<classpath>
<dirset dir="${root.dir}" includes="${class.dirs}/**/*.class"/>
</classpath>
或
<classpath>
<pathelement location="${class.dirs}" />
</classpath>
但是这个例子当然行不通.
But this example does not work, of course.
推荐答案
您可以设置路径以包含特定目录中的所有 .class 文件:
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>
但是,如果要将此路径用作类路径,则只需引用根文件夹即可,否则将在包名称转换为目录时得到ClassNotFoundError
:
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>
然后在使用时通过其 id 引用路径(例如用于类路径):
Then reference the path by its id when using (e.g. for classpath):
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
这篇关于如何将ant中一组目录中的所有类添加到类路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!