java - 如何显示 Groovy AntBuilder 类路径中包含的所有资源?

标签 java ant groovy antbuilder

我正在使用 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/

相关文章:

java - 自定义 ImageView android

java - mockito-groovy-支持不工作

java - 从 WSDL 生成的自顶向下 Java 服务中的 CXF 3.0.3 部署错误

java - 试图调用子方法,但将其实例化为父方法

java - ant build过程中修改代码的最佳实践

java - 将 NetBeans 项目从 Windows 转移到 Linux VM 时 Ant 构建出错

java添加到路径时,java.exe不被识别为内部或外部命令可操作程序或批处理文件

javascript - 生成加权随机数

java - Spring Boot 退出代码生成器 - 实现不起作用

java - Joda Time : First day in this year's ISO week 1