Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get classpath in Groovy?

Tags:

groovy

How can I get current value of CLASSPATH in Groovy?

like image 619
yegor256 Avatar asked Mar 06 '11 18:03

yegor256


People also ask

How do I find out my classpath?

Select Start -> Control Panel -> System -> Advanced -> Environment Variables -> System Variables -> CLASSPATH. If the Classpath variable exists, prepend .;C:\introcs to the beginning of the CLASSPATH varible. If the CLASSPATH variable does not exist, select New.

What is classpath in command-line?

Classpath in Java is the path to the directory or list of the directory which is used by ClassLoaders to find and load classes in the Java program. Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command-line option or Class-Path attribute in manifest.


1 Answers

Shameless stolen from http://blog.blindgaenger.net/print_groovys_classpath_for_debugging.html This code will go up the classloader tree and printout each classloader and the associated classpath.

def printClassPath(classLoader) {
  println "$classLoader"
  classLoader.getURLs().each {url->
     println "- ${url.toString()}"
  }
  if (classLoader.parent) {
     printClassPath(classLoader.parent)
  }
}
printClassPath this.class.classLoader
like image 70
M Smith Avatar answered Oct 16 '22 13:10

M Smith