java - 使用文件集和路径元素在 build.xml 中设置类路径的区别

标签 java ant classpath build.xml

我有一个构建文件,它声明了如图所示的类路径

<path id="compile.classpath">
    <fileset dir="${basedir}/lib"    includes="**"/>        
    <fileset dir="${jboss.home}/lib" includes="**"/>        
    <pathelement path ="${build.classes.dir}"/>
</path>

我试着查看文档,但我无法理解使用 路径元素

我知道 ID 用于在执行任务时引用此类路径,文件集包含 jar 文件。

编辑 1: 我的疑问是为什么我们不能使用 fileset 来包含类文件来代替 pathelement

最佳答案

最新编辑:

My doubt is Why can't we use fileset to include the class files in place of pathelement?

如果您使用文件集,那么您将向路径添加一组类文件,如下所示:

CLASSPATH=classes/MyClass1.class:classes/MyClass2.class:classes/MyClass3.class:....

当 Java 希望看到的只是:

CLASSPATH=classes

只有 jar(和 WAR、EAR 等)文件明确列在类路径中(Java 将打开它们并加载它们的类文件),因此需要 ANT 中的文件集。

更新

这是 Oracle 文档:

Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:

  • For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
  • For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
  • For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

关于java - 使用文件集和路径元素在 build.xml 中设置类路径的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14439828/

相关文章:

java - 从命令行编译 .java 文件 - 外部库、类路径

java - Ubuntu 现在可以设置 java 路径

java - 如果在其他配置文件中添加路由,为什么主配置中的路由未加载?

java - PAX-URL : "Protocol not supported" at Felix's startup

java - Win7 64 位 jre7 & jdk1.7.0_25 中的导入按钮错误 java.security.accesscontroleexception 访问被拒绝(java.util.propertypermission user.dir 读取)

java - 将 Ant builder 集成到 Eclipse 中 : Relative paths for refresh scope working set

Java:获取另一个应用程序的类路径

java - Jackson DataBing 版本 2.9.5 无法将对象解析为 JSON 字符串

java - 如何使 Redline RPM 库与 Ant 一起工作?

spring - 未找到安装任务