0
我遍历目录载入我的jar文件Groovy的装载jar文件
import groovy.io.FileType
def list = []
def dir = new File("C:\\Whatever\\")
dir.eachFileRecurse (FileType.FILES) {
if(it.name.endsWith('.jar')) {
println it
this.getClass().classLoader.rootLoader.addURL(new File(it).toURI().toURL())
}
}
而且我得到以下错误:
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(java.io.File)
at ConsoleScript21$_run_closure1.doCall(ConsoleScript21:9)
at ConsoleScript21.run(ConsoleScript21:6)
我在做什么错?为什么我不能像这样加载我的jar文件?
最有可能抱怨你使用'新文件中的错误(它)'而'它''已经是'File' – Aaron
除非闭包是单线,否则我总是喜欢输入参数类型(如果适用)和名称,而不是使用“it”。 – Steinar