我正在使用 Groovy 的 AntBuilder 构建一个 Java 项目。在缺少看起来确实应该包含的类的地方发生错误。我想打印出包含在以下类路径闭包中的每个 JAR/WAR,但我不知道该怎么做。每次我尝试显示类路径的内容时,它都显示为空。关于如何执行此操作的任何想法?
作为引用,这里是 java 构建任务和类路径。这发生在 new AntBuilder().with { }
闭包中。
javac srcdir: sourceDir, destdir: destDir, debug: true, target: 1.6, fork: true, executable: getCompiler(), {
classpath {
libDirs.each { dir -> fileset dir: dir, includes: "*.jar,*.war" }
websphereLib.each { dir -> fileset dir: dir, includes: "*.jar*" }
if (springLib.exists()) { fileset dir: springLib, includes: "*.jar*" }
was_plugins_compile.each { pathelement location: was_plugins_dir + it }
if (webinf.exists()) { fileset dir: webinf, includes: "*.jar" }
if (webinfclasses.exists()) { pathelement location: webinfclasses }
}
}
最佳答案
您可以将 javac 任务之外的类路径定义为 Ant 路径。然后您可以保存生成的 org.apache.tools.ant.types.Path
对象以获取其路径条目并将它们打印到 System.out。在 javac 任务中,您可以使用其 refid 引用类路径:
new AntBuilder ().with {
compileClasspath = path(id: "compile.classpath") {
fileset(dir: "libs") {
include(name: "**/*.jar")
}
}
// print the classpath entries to System.out
compileClasspath.list().each { println it }
javac (...) {
classpath (refid: "compile.classpath")
}
}
关于java - 如何显示 Groovy AntBuilder 类路径中包含的所有资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5952137/