2011-05-10 3 views
1

Groovy의 AntBuilder를 사용하여 Java 프로젝트를 빌드하고 있습니다. 클래스가 누락되어 실제로 포함 된 것처럼 보이는 오류가 발생합니다. 다음 클래스 패스 클로저에 포함 된 모든 JAR/WAR를 출력하고 싶습니다.하지만 어떻게해야하는지 알 수 없습니다. classpath의 내용을 표시하려고 할 때마다 null로 표시됩니다. 이 작업을 수행하는 방법에 대한 아이디어가 있습니까?Groovy AntBuilder 클래스 경로에 포함 된 모든 리소스를 표시하는 방법은 무엇입니까?

다음은 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 } 
    } 
} 

답변

3

당신은 개미 경로로 javac의 작업 외부 클래스 경로를 정의 할 수 있습니다. 그런 다음 결과로 얻은 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") 
    } 
} 
+0

감사합니다. 비슷한 것을 시도했지만 list()의 개별 항목이 아닌 전체 경로를 println하려고했습니다. –

+1

그래, 효과가! –