Eclipse 基于教程的代码中的MissingMethodException,昨天有效
我对Groovy和HttpBuilder库有一个奇怪的问题。首先要注意的是,我对Groovy还不熟悉 我的代码基于教程。它只是从HTTP服务器加载文件列表。代码昨天起作用,今天(在工作区构建之后)不起作用 问题是:Eclipse 基于教程的代码中的MissingMethodException,昨天有效,eclipse,groovy,httpbuilder,Eclipse,Groovy,Httpbuilder,我对Groovy和HttpBuilder库有一个奇怪的问题。首先要注意的是,我对Groovy还不熟悉 我的代码基于教程。它只是从HTTP服务器加载文件列表。代码昨天起作用,今天(在工作区构建之后)不起作用 问题是: Caught: groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (
Caught: groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, pl.linfo.groovy.samples.HttpTest$_main_closure1)
Possible solutions: request(groovyx.net.http.Method, groovy.lang.Closure)
代码是:
def http = new HTTPBuilder( 'http://nbp.pl/Kursy/xml/dir.txt' )
http.request( GET, TEXT ) {
response.success = { resp, reader ->
println "${resp.statusLine}"
files = reader.text.split ('\r\n')
}
response.'404' = {
println "Not found!"
return
}
};
运行环境是Eclipse3.6
我假设问题是groovy编译问题,重新编译后的groovy代码片段不再匹配闭包。但是,作为Groovy的新手,我很难了解到底发生了什么,所以请提供帮助。这一定是EclipseGroovy插件的问题。在使用groovy解释器运行时,您发布的代码对我来说非常有效
$ cat hbuildertest.groovy
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://nbp.pl/Kursy/xml/dir.txt' )
http.request( GET, TEXT ) {
response.success = { resp, reader ->
println "${resp.statusLine}"
files = reader.text.split ('\r\n')
}
response.'404' = {
println "Not found!"
return
}
};
$ groovy hbuildertest.groovy
May 19, 2011 12:59:08 AM groovyx.net.http.ParserRegistry getCharset
WARNING: Could not find charset in response
HTTP/1.1 200 OK
$
还有带签名的方法:
public Object request( Method m, Object contentType, Closure configClosure )
throws ClientProtocolException, IOException
至少从库的0.3.0版本开始就存在于类中。正如我所写的,代码是为我运行的,并且是在Eclipse中运行的。然而,记事本驱动的开发显然不适合我,我希望它能在IDE中工作:(