English 中文(简体)
如何在蚂蚁目录组的所有类中添加类路径?
原标题:How to add to classpath all classes from set of directories in ant?
  • 时间:2012-05-22 14:41:10
  •  标签:
  • ant

如何从一组目录中添加所有类类到类路径?

我有以下财产:

类. dirs= lib1dir, lib2dir, lib3dir 类. dir = 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>

但这一例子当然行不通。

问题回答

您可以设置包含您指定目录中所有. 类文件的路径 :

<path id="mypath"> 
  <fileset dir="${root.dir}">
    <include name="lib1dir/**/*.class lib2dir/**/*.class lib3dir/**/*.class"/>
  </fileset>
</path> 

但是,如果您想要使用此路径作为类路径, 您只需要引用根文件夹, 否则您将获得 < code> Class NotFoundError , 当软件包名称转换为目录时 :

<path id="build.classpath"> 
  <dirset dir="${root.dir}">
    <include name="lib1dir lib2dir lib3dir"/>
  </dirset>
</path> 

然后使用时用其 ID 参考路径(例如,为类路径) :

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />




相关问题
i want to continously run my java threads

I am running my java application where i have used threads... i am running this application using ant command on the terminal.. But when i close my terminal or press ctrl+c,then java program which was ...

Subant targets instead of ant

I m having a problem with subant and have no ideas any more. Can anyone help? Using Ant to replace some strings for other (i.e Productname and Version for "Foo" and "1.2") I used ...

java ant buildfile for project with dependencies

I am new to ant, but am trying to create an ant script that builds my current proeject with another project as a dependency. I have the ant script building my current project, but am unsure how to add ...

Building Apache Hive - impossible to resolve dependencies

I am trying out the Apache Hive as per http://wiki.apache.org/hadoop/Hive/GettingStarted and am getting this error from Ivy: Downloaded file size doesn t match expected Content Length for http://...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签