Created
February 28, 2015 00:46
-
-
Save rmorenobello/281ec6919ef71b232dce to your computer and use it in GitHub Desktop.
Get the full system path of the running groovy script from itself
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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