I need to get at runtime the full path to the script file in Groovy 2.3. I actually have the same problem as described here: getting the path to the Groovy source file at runtime .
My script can be executed from GroovyShell or not.
My script is located at:
C:\users\myname\documents\scripts\myscript.groovy
=> I just want to get this path at runtime.
If I use the accepted solution:
println new File(".").absolutePath
what i actually get:
C:\groovy-2.3.7\.
which is the Groovy home folder. This is not true. Another suggested answer:
URL scriptUrl = getClass().classLoader.resourceLoader.loadGroovySource(getClass().name)
, script Groovy load groovy -starter.conf. null. , , , , script .
JIRA, :
JIRA-1642
, , @SourceURI . , . , : SourceURI
@groovy.transform.SourceURI def sourceURI
assert sourceURI instanceof java.net.URI
path = sourceURI.toString()
println "path = $path"
(groovy 2.3.7) - , :
path = data:,@groovy.transform.SourceURI%20def%20sourceURI%0A%0A%20assert%20sourceURI%20instanceof%20java.net.URI%0Apath%20=%20sourceURI.toString()%0Aprintln%20%22path%20=%20$path%22
@SourceURI script?