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

发布于 2024-11-06 09:05:39 字数 846 浏览 3 评论 0原文

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

I am using Groovy's AntBuilder to build a Java project. An error is occurring where classes are missing that really look like they should be included. I want to print out every JAR/WAR that's included in the following classpath closure, but I can't figure out how to do that. Every time I've tried to display the contents of classpath, it shows up as null. Any ideas on how to do this?

For reference, here's the java build task and the classpath. This occurs within a new AntBuilder().with { } closure.

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 }
   }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情独悲 2024-11-13 09:05:39

您可以将 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")
    }
}

You could define the classpath outside the javac task as an Ant path. Then you can save the resulting org.apache.tools.ant.types.Path object to get its path entries and print them to System.out. Within the javac task you can reference the classpath with its 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")
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文