且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在groovy中获得正在运行的脚本的路径?

更新时间:2023-12-05 14:08:52

您正确的是 new File(。)。getCanonicalPath ()不起作用。返回工作目录

You are correct that new File(".").getCanonicalPath() does not work. That returns the working directory.

获取脚本目录

To get the script directory

scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent

获取脚本文件路径

To get the script file path

scriptFile = getClass().protectionDomain.codeSource.location.path