Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovysh葡萄导入不工作_Groovy_Grape_Groovyshell_Groovysh - Fatal编程技术网

Groovysh葡萄导入不工作

Groovysh葡萄导入不工作,groovy,grape,groovyshell,groovysh,Groovy,Grape,Groovyshell,Groovysh,我正在使用Groovysh,我需要用Grape加载一些类。现在我正在尝试: > @Grab(group='group.example', module='module.example', version='1.2.3') > import group.example.TheClass > theClass = new TheClass() 然而,在我输入导入之后,Groovy说 groovysh_evaluate:4:无法解析类 奇怪的是,如果我尝试这样做: > @Gr

我正在使用Groovysh,我需要用Grape加载一些类。现在我正在尝试:

> @Grab(group='group.example', module='module.example', version='1.2.3')
> import group.example.TheClass
> theClass = new TheClass()
然而,在我输入导入之后,Groovy说

groovysh_evaluate:4:无法解析类

奇怪的是,如果我尝试这样做:

> @Grab(group='group.example', module='module.example', version='1.2.3')
> import group.example.TheClass
> theClass = new TheClass()
> import group.example.TheClass
> theClass = new TheClass()

第一次导入和声明失败,但第二次成功。这可能是个错误,也可能是我做错了什么。我目前正在使用Groovy 2.4.12,非常感谢您的帮助。当我在脚本中尝试同样的东西时,效果很好,所以我很困惑。我也尝试过使用解释器模式,但也没有运气。

我发现如果

import group.example.TheClass
我知道

它起作用了。这似乎仍然是一个bug,但这里有一个解决方案,以防其他人遇到此问题。

尝试以下方法:

groovy:000> import groovy.grape.Grape
===> [import groovy.grape.Grape]
groovy:000> Grape.grab(group:'net.sourceforge.htmlunit', module:'htmlunit', version:'2.44.0')
===> null
groovy:000> import com.gargoylesoftware.htmlunit.WebClient
===> [import groovy.grape.Grape, import com.gargoylesoftware.htmlunit.WebClient]
groovy:000> import groovy.grape.Grape
===> [import groovy.grape.Grape]
groovy:000> Grape.grab(group:'net.sourceforge.htmlunit', module:'htmlunit', version:'2.44.0')
===> null
groovy:000> import com.gargoylesoftware.htmlunit.WebClient
===> [import groovy.grape.Grape, import com.gargoylesoftware.htmlunit.WebClient]