title: Include classes in a groovy script
body: <p>How can I include a few classes in a Groovy script?</p>
  
  <p>(This question has nothing to do with REST, but I use REST to put the question in the right context)</p>
  
  <p>Background:
  I am developing a CLI in groovy to get status information from a service we are running. The status information is exposed as a REST interface. </p>
  
  <p>Depending on the argument I give on the CLI, different paths are called on the REST interface. I have also put the actual REST communication in a class hierarchy to be able to reuse the code and this is where I have the problem. How can I include the class hierarchy in my groovy script in an easy way?</p>
  
  <p>Groovy CLI-script <code>RestCli.groovy</code></p>
  
  <pre><code>import restcli.RestA
  import restcli.RestB
  
  if(args[0] == "A") {
      new RestA().restCall()
  }
  else if(args[0] == "B") {
      new RestB().restCall()
  }
  </code></pre>
  
  <p>Super class for the hierarcy <code>restcli/RestSuper.groovy</code> </p>
  
  <pre><code>package restcli
  
  abstract class RestSuper {
  
      protected def restCall(String path) {
          println 'Calling: ' +path
      } 
  
      abstract def restCall()
  
  }
  </code></pre>
  
  <p>Two classes to implement different calls. <code>restcli/RestA.groovy</code></p>
  
  <pre><code>package restcli
  
  class RestA extends RestSuper {
  
      def restCall() {
          restCall("/rest/AA")
      }       
  
  }
  </code></pre>
  
  <p>and <code>restcli/RestB.groovy</code></p>
  
  <pre><code>package restcli
  
  class RestB extends RestSuper {
  
      def restCall() {
          restCall("/rest/BB")
      }
  
  }
  </code></pre>
  
  <p>The result I want to get is simply:</p>
  
  <pre><code>&gt; groovy RestCli.groovy B
  Calling: /rest/BB
  </code></pre>
  
  <p>Any ideas on how to do this?</p>
  
  <p>I would actually like to avoid creating a jar file and then use the <code>-classpath</code> option, because I'm also using <code>@Grab</code> to get http-builder and if I use <code>-classpath</code> then I'm getting problems like this one: <code>java.lang.NoClassDefFoundError: groovyx.net.http.HTTPBuilder</code></p>