title: Groovy:unable to resolve class groovyx.net.http.RESTClient
body: <p>I am learning groovy for a scripting package called geoscript-groovy. I followed the groovy REST tutorial <a href="http://rest.elkstein.org/2008/02/using-rest-in-groovy.html" rel="noreferrer">here</a> and tested the following code:</p>
  
  <pre><code>import groovyx.net.http.RESTClient
  
  def client = new RESTClient( 'http://www.acme.com/' )
  def resp = client.get( path : 'products/3322' ) // ACME boomerang
  </code></pre>
  
  <p>However, I got an error at the <code>import</code> statement saying:</p>
  
  <pre><code>Groovy:unable to resolve class groovyx.net.http.RESTClient
  </code></pre>
  
  <p>I searched around, and there are many questions and answers for this error message, e.g., <a href="https://stackoverflow.com/questions/21487301/import-groovyx-net-http-restclient-in-groovy-class">import groovyx.net.http.RESTClient in Groovy class</a> , and <a href="https://stackoverflow.com/questions/24353035/restclient-grails-import-fails">RestClient Grails Import fails</a>. However, they all for grails, which I don't use and am not very familiar with.</p>
  
  <p>My question is</p>
  
  <p>How should I fix this error if I have groovy only? (My version of groovy is installed under Ubuntu 12.04 with the following commands).</p>
  
  <pre><code>sudo apt-add-repository ppa:groovy-dev/groovy
  sudo apt-get update
  sudo apt-get install groovy
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>-- EDIT ---</p>
  
  <p>I added @Grab statements as suggested, and put up a two-line <code>rest1.groovy</code> file as follows:</p>
  
  <pre><code>@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
  import groovyx.net.http.RESTClient
  </code></pre>
  
  <p><code>groovyConsole rest1.groovy</code> seems to run OK. But <code>groovysh &lt; rest1.groovy</code> is still giving me an error (as shown below). I guess I need to have this run in a <code>groovysh</code>-like environment because the groovy script is called in the background as a web service. Without the <code>@Grab</code> line, the service generates an Exception. With the <code>@Grab</code> line, the service won't even register. Is there a more permanent way of including necessary dependencies for <code>groovyx.net.http.RESTClient</code> than a per script grab (e.g. an <code>apt-get</code> or manual copying of something)?</p>
  
  <pre><code>groovysh &lt; rest1.groovy
  Groovy Shell (1.8.6, JVM: 1.7.0_72)
  Type 'help' or '\h' for help.
  -------------------------------------------------------------------------------
  groovy:000&gt; @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
  groovy:001&gt; 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 to resolve class groovyx.net.http.RESTClient
   @ line 1, column 1.
     import groovyx.net.http.RESTClient
  </code></pre>