title: Why doesn't groovy use classpath argument?
body: <p>Invoking a groovy script using CLASSPATH prefix as follows works fine:</p>
  
  <pre><code>CLASSPATH=/path/to/classes groovy -e "(new stuff.XMLUtils()).printIt('test string')"
  </code></pre>
  
  <p>but changing it to use the classpath arg doesn't:</p>
  
  <pre><code>groovy -classpath /path/to/classes -e "(new stuff.XMLUtils()).printIt('test string')"
  </code></pre>
  
  <p>and gives the error:</p>
  
  <pre><code>script_from_command_line: 1: unable to resolve class stuff.XMLUtils
  </code></pre>
  
  <p>Can anyone explain why this is? (The stuff.XMLUtils is just some groovy script i've compiled into /path/to/classes
  )</p>
  
  <p>I've done some investigation, and using the following groovy script to dump the classloader</p>
  
  <pre><code>def printClassPath(classLoader) {
    println "$classLoader"
    classLoader.getURLs().each {url-&gt;
       println "- ${url.toString()}"
    }
    if (classLoader.parent) {
       printClassPath(classLoader.parent)
    }
  }
  printClassPath this.class.classLoader
  </code></pre>
  
  <p>With the <code>-classpath</code> arg, i see no entry in the classloader for the passed in classpath arg, (in fact, the only directory is the current working dir), e.g.:</p>
  
  <pre><code>groovy.lang.GroovyClassLoader$InnerLoader@4911b910
  groovy.lang.GroovyClassLoader@18203c31
  sun.misc.Launcher$AppClassLoader@35a16869
  - file:/usr/share/java/ant.jar
  - ... (removed for brevity)
  - file:/home/admin/groovy/
  sun.misc.Launcher$ExtClassLoader@77cde100
  - file:/usr/java/jdk1.6.0_23/jre/lib/ext/sunjce_provider.jar
  - ...
  </code></pre>
  
  <p>Using the <code>CLASSPATH=...</code> version shows that the PWD entry above is replaced by the value i've set in the variable.</p>
  
  <p>And if I add debug to the groovy shell executable, the difference in the java call is that the <code>-classpath</code> arg version adds no entry to java's classpath entry (which is ultimately why it's giving a class not found error), but the <code>CLASSPATH=...</code> version does add the path.</p>
  
  <p>Is this a bug in groovy?</p>
  
  <p>EDIT: simple failing example</p>
  
  <pre><code>- - - - xu.groovy
  package stuff
  def printIt(string) { println string }
  - - - -
  
  groovyc -d classes xu.groovy
  groovy -cp classes -e "(new stuff.xu()).printIt('test')"  # fails
  CLASSPATH=classes groovy -e "(new stuff.xu()).printIt('test')"  # works
  </code></pre>
  
  <p>If I remove the package and references to <code>stuff</code> the failing example will work fine.</p>