Thursday, January 7, 2010

Viewing Groovy Application's Classpath

Because the set of classes that Groovy applications see is wider than the set standard Java applications see, it can be helpful to see what classes are already on the Groovy classpath. This is very easy to do and the one line of executable Groovy to do this is shown in the next code listing.


#!/usr/bin/env groovy
this.class.classLoader.rootLoader.URLs.each{ println it }


The above code takes advantage of the Groovy RootLoader. This RootLoader is often used to dynamically add a library to the Groovy application's classpath, but, as the example here shows, can also be used to see what Groovy sees.

When the above code is executed, the results shown next are seen.


file:/C:/java/examples/groovyExamples/displayGroovyClasspath/./
file:/C:/Program%20Files/Java/jre6/lib/ext/QTJava.zip
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/ant-1.7.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/ant-junit-1.7.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/ant-launcher-1.7.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/antlr-2.7.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/asm-3.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/asm-analysis-3.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/asm-commons-3.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/asm-tree-3.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/asm-util-3.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/balloontip_2009-01-2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-anim-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-awt-util-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-bridge-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-codec-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-css-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-dom-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-ext-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-extension-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-gui-util-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-gvt-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-parser-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-script-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-svg-dom-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-svggen-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-swing-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-transcoder-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-util-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/batik-xml-1.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/bsf-2.4.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/commons-cli-1.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/commons-logging-1.1.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/cssbuilder-0.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/cssparser-0.9.5.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/Filters.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/flamingo-4.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/flamingo-4.0dev.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/flamingobuilder-0.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/forms-1.2.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/fxbuilder-0.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/gant-1.9.0_groovy-1.7.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/gfxbuilder-core-0.2.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/gfxbuilder-svg-0.2.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/gfxbuilder-swingx-0.2.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/gpars-0.9.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/groovy-1.7.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/ivy-2.1.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jacob-1.14.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/JFXtras-0.5.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jide-oss-2.6.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jidebuilder-2.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jline-0.9.94.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jsilhouette-geom-0.3.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jsp-api-2.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/jsr166y-070108.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/junit-4.7.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/l2fprod-common-all.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/macwidgets-0.9.4.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/macwidgetsbuilder-0.2.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/maven-ant-tasks-2.0.10.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/miglayout-3.6.3-swing.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/MultipleGradientPaint.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/netty-3.1.5.GA.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/sac-1.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-ie-6-tlb-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-office-2K3-tlb-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-sapi-tlb-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-scripting-tlb-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-wbem-tlb-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/scriptom-wsh-tlb-1.6.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/servlet-api-2.4.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/spock-core-0.3.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/svg-salamander-1.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/swing-worker-1.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/swingx-1.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/swingx-beaninfo-0.9.5.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/swingx-ws.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/swingxbuilder-0.1.6.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/swingxtrasbuilder-0.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/timingframework-1.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/trident-1.0.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/tridentbuilder-0.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/xml-apis-ext-1.3.04.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/xstream-1.3.1.jar
file:/C:/Program%20Files/Groovy/Groovy-1.7.0/lib/xswingx-0.2.jar
file:/C:/Program%20Files/Java/jdk1.6.0_14/lib/tools.jar


The results returned from that simple Groovy script indicate what is already advertised about where Groovy automatically looks for classes and JARs: the current directory, the JRE extension mechanism directory, the Groovy installation's lib directory (%GROOVY_HOME%\lib or ${GROOVY_HOME}/lib), and the JDK's tools.jar. Had I specified any classes or JARs on the classpath using the -cp option, those would have been displayed here as well.