rest - Groovy:unable to resolve class groovyx.net.http.RESTClient -
rest - Groovy:unable to resolve class groovyx.net.http.RESTClient -
i learning groovy scripting bundle called geoscript-groovy. followed groovy rest tutorial here , tested next code:
import groovyx.net.http.restclient def client = new restclient( 'http://www.acme.com/' ) def resp = client.get( path : 'products/3322' ) // acme boomerang
however, got error @ import
statement saying:
groovy:unable resolve class groovyx.net.http.restclient
i searched around, , there many questions , answers error message, e.g., import groovyx.net.http.restclient in groovy class , , restclient grails import fails. however, grails, don't utilize , not familiar with.
my question is
how should prepare error if have groovy only? (my version of groovy installed under ubuntu 12.04 next commands).
sudo apt-add-repository ppa:groovy-dev/groovy sudo apt-get update sudo apt-get install groovy
thanks.
-- edit ---
i added @grab statements suggested, , set two-line rest1.groovy
file follows:
@grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7') import groovyx.net.http.restclient
groovyconsole rest1.groovy
seems run ok. groovysh < rest1.groovy
still giving me error (as shown below). guess need have run in groovysh
-like environment because groovy script called in background web service. without @grab
line, service generates exception. @grab
line, service won't register. there more permanent way of including necessary dependencies groovyx.net.http.restclient
per script grab (e.g. apt-get
or manual copying of something)?
groovysh < rest1.groovy groovy shell (1.8.6, jvm: 1.7.0_72) type 'help' or '\h' help. ------------------------------------------------------------------------------- groovy:000> @grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7') groovy:001> import groovyx.net.http.restclient error org.codehaus.groovy.tools.shell.commandexception: invalid import definition: 'import groovyx.net.http.restclient'; reason: startup failed: script1413902882282760571375.groovy: 1: unable resolve class groovyx.net.http.restclient @ line 1, column 1. import groovyx.net.http.restclient
you need grape line create sure groovy script has jar need in classpath. set @ top of script:
@grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
note, can't see rest of script, there may other modules need grab too. check here more possibilities: http://groovy.codehaus.org/modules/http-builder/doc/rest.html
edit
well, glad works part of way now. far groovysh goes, don't know of way have groovysh dynamically dependent libraries, need is, part of script install, set jar need in directory (call "lib" or such), , add together argument groovysh call: groovysh -cp ./lib < script.groovy this: http://groovy.codehaus.org/groovy+shell
the jar want should available via maven using artifact specification @grab line.
rest groovy
Comments
Post a Comment