【发布时间】:2017-11-17 14:53:02
【问题描述】:
以下磁盘设置
temp/
Folder/
myPackage/
Person.groovy
test.groovy
script.groovy
'script.groovy'文件内容
import myPackage.Person
new Person()
'test.groovy'文件内容
def cl = new GroovyClassLoader(this.getClass().classLoader)
cl.addURL (new URL ('file://C:/temp/Folder'))
new GroovyShell(cl).evaluate (new File ('C:/temp/script.groovy'))
问题:
"groovy c:\temp\test.groovy" 结果
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
failed:
C:\temp\script.groovy: 1: unable to resolve class myPackage.Person
@ line 1, column 1.
import myPackage.Person
^
1 error
但是 'groovy -cp C:\temp\Folder c:\temp\test.groovy' 当然可以。
我的逻辑错误在哪里?不应该从添加的类路径加载准备好的类加载器类Person吗?
问候, 格特
【问题讨论】: