开发者

HTTP client library in Groovy

I am interested in querying a REST API using Groovy. I found HttpURLClient which seems like it should do what I want, but Groovy Console complains "unable to resolve class HttpURLClient" I found this link t开发者_Go百科hat has sample code for HttpURLClient: http://groovy.codehaus.org/modules/http-builder/doc/httpurlclient.html

But copy-pasting that code gives the same error.

I also looked into using HTTPBuilder which also seems like it might work, but that gave similar errors as well.

Any idea what I need to do to get these to work?

Thanks


Have you installed the library?

http://groovy.codehaus.org/modules/http-builder/download.html

edit

If you want to use the SNAPSHOT release, you can add the resolver in as an annotation, rather than editing the xml file;

@GrabResolver( name='codehaus.snapshot', root='http://snapshots.repository.codehaus.org', m2compatible='true' )
@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2-SNAPSHOT' )
import groovyx.net.http.*

At the top of your script should do it


Do you know how I can avoid using the runtime "Grabbing" altogether? I want to install it on my system so that I can just import it and have it work, without the @Grab annotation. I tried installing on the command line but, while that succeeded, I still need to have

Hi,

check your user home for:

ls .groovy/grapes/

There you should find the jars you installed with Grape before.

Probably Groovy does not know yet, where it can find these grapes. Therefore you have to add the Grape path to your Groovy Classloading Configuration which can be found in the place, where you installed Groovy:

${groovy.home}/conf/groovy-starter.conf

Add this line at the end for loading Grapes:

# load grape libraries
load !{user.home}/.groovy/grapes/**/*.jar

Be aware that you might have to remove either xml-apis or xerces from your Grapes in order for the HttpClient to function correctly. (This might be just a problem using Grails and the HttpClient)


Try using the command line in the $GROOVY_HOME/bin folder

grape resolve org.codehaus.groovy.modules.http-builder http-builder 0.6

sudo grape install org.codehaus.groovy.modules.http-builder http-builder 0.6

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜