如何添加从集蚂蚁目录classpath中的所有类? [英] How to add to classpath all classes from set of directories in ant?

查看:175
本文介绍了如何添加从集蚂蚁目录classpath中的所有类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加从组目录classpath中的所有类?

我有以下属性:


  

class.dirs = lib1dir,lib2dir,lib3dir


有班下这些目录。结果
是否有可能增加在这些目录中的所有类类路径?

是这样的:

 <&类路径GT;
   < dirset DIR =$ {} root.dir包括=$ {} class.dirs / ** / *类。/>
< /类路径>

 <&类路径GT;
   < pathelement位置=$ {} class.dirs/>
< /类路径>

但这个例子不工作的,当然。


解决方案

您可以设置一个路径,从特定的目录包括所有的.class文件:

 <路径ID =mypath中>
  <文件集DIR =$ {} root.dir>
    &所述;包括名称=lib1dir / ** / *类lib2dir / ** / *类lib3dir / ** / *类。/>
  < /文件集>
< /路径>

不过,如果你想使用此路径作为classpath中,你只需要引用根文件夹,否则你将得到 ClassNotFoundError S作为包名翻译成目录:

 <路径ID =build.classpath>
  < dirset DIR =$ {} root.dir>
    <包括姓名=lib1dir lib2dir lib3dir/>
  < / dirset>
< /路径>

然后,通过其ID使用(例如,用于类路径)时引用的路径

 < javac的SRCDIR =$ {}对于src.dirDESTDIR =$ {} build.dirclasspathref =build.classpath/>

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.

解决方案

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" />

这篇关于如何添加从集蚂蚁目录classpath中的所有类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆