Skip to content

Instantly share code, notes, and snippets.

@rmorenobello
Created February 28, 2015 00:46
Show Gist options
  • Save rmorenobello/281ec6919ef71b232dce to your computer and use it in GitHub Desktop.
Save rmorenobello/281ec6919ef71b232dce to your computer and use it in GitHub Desktop.
Get the full system path of the running groovy script from itself
// http://stackoverflow.com/a/1169196/2906290
/*
when calling
c:\scripts\MyScript.groovy from c:\users\Scott\
I wanted to know c:\scripts\.
*/
def scriptFile = getClass().protectionDomain.codeSource.location.path
def scriptDir = new File(scriptFile).parent
println scriptDir
println scriptFile
// http://stackoverflow.com/a/2314475/2906290
/*
This makes sense if you are running the Groovy code as a script, otherwise the whole idea gets a little confusing, IMO.
The workaround is here: http://jira.codehaus.org/browse/GROOVY-1642
Basically this involves changing startGroovy.sh to pass in the location of the Groovy script as an environment variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment