title: Groovy script cannot import java code
body: <p>The problem I have is larger, but I will simplify the concept that is failing. </p>
  
  <p>I am working on Ubuntu.</p>
  
  <p>Here is my directory structure:</p>
  
  <p>~/mydirectory</p>
  
  <p>--/groovy</p>
  
  <p>--/myjavafiles</p>
  
  <p>I have a script, script.groovy, that lives inside ~/mydirectory/groovy and a java file called Hello.java that lives inside ~/mydirectory/myjavafiles. script.groovy has the following inside:</p>
  
  <pre><code>#!/usr/bin/env groovy
  
  package groovy;
  import myjavafiles.Hello;
  
  println("hello");
  </code></pre>
  
  <p>Hello.java has this:</p>
  
  <pre><code>package myjavafiles;
  public class Hello {
     public Hello() {
         System.out.println("hello");
     }
  }
  </code></pre>
  
  <p>I have tried running:</p>
  
  <pre><code>$./script.groovy
  </code></pre>
  
  <p>aswell as</p>
  
  <pre><code>$groovy script.groovy
  </code></pre>
  
  <p>But I only get an error, "unable to find class".</p>
  
  <p><strong>Here are the steps I have taken to fix this error:</strong></p>
  
  <p>i. set CLASSPATH = ~/mydirectory, that didn't work.</p>
  
  <p>ii. used </p>
  
  <pre><code>$jar cf myjavafiles.jar myjavafiles
  </code></pre>
  
  <p>and placed myjavafiles.jar in ~/.groovy/lib, that didn't work. </p>
  
  <p>iii. As mentioned <a href="https://stackoverflow.com/questions/306139/how-do-i-include-jars-in-a-groovy-script">here</a>, I tried to modify groovy.script as follows: </p>
  
  <pre><code>#!/bin/bash
  //usr/bin/env groovy
  package groovy;
  import myjavafiles.Hello;
  
  println("hello");
  </code></pre>
  
  <p>That also did not work.</p>
  
  <p><strong>Other, maybe relevant</strong></p>
  
  <p>If it's any help, I'm using Ubuntu, Java 7 and Groovy 2.1.5</p>
  
  <p>GROOVY_HOME=/opt/groovy/groovy-2.1.5/</p>
  
  <p>and $GROOVY_HOME/bin is in my PATH</p>
  
  <p>I would greatly appreciate any help.</p>