How do you get the path of the running script in groovy?

后端 未结 6 1704
悲哀的现实
悲哀的现实 2020-12-02 11:54

I\'m writing a groovy script that I want to be controlled via a properties file stored in the same folder. However, I want to be able to call this script from anywhere. Wh

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 12:24

    One more solution. It works perfect even you run the script using GrovyConsole

    File getScriptFile(){
        new File(this.class.classLoader.getResourceLoader().loadGroovySource(this.class.name).toURI())
    }
    
    println getScriptFile()
    

提交回复
热议问题