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