我有一个构建文件,它声明了如图所示的类路径
<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/