Reputation: 229988
I'm trying to use groovyc, but something is not right:
>echo println("Hello world") > test.groovy
>groovy test.groovy
Hello world
>groovyc test.groovy
>java -cp C:\utils\groovy-1.8.1\embeddable\groovy-all-1.8.1.jar test
Error: Could not find or load main class test
>dir test.class
...
11/10/2011 02:54 PM 7,104 test.class
What am I missing?
Upvotes: 18
Views: 24499
Reputation: 1528
I am not sure these snippets will work, since class with main method is missed. Proper command line is:
java -cp /path/to/groovy/embeddable/groovy-all-1.8.1.jar groovy.lang.GroovyShell test.groovy
Upvotes: 7
Reputation: 3712
Make sure that if you are using a unix based system (Linux or Mac), then you need colon instead of semicolon for classpath entry separator:
>java -cp /path/to/groovy/embeddable/groovy-all-1.8.1.jar:. test
Hello, world
Upvotes: 8
Reputation: 10239
When you specify the classpath with -cp
switch, its default value (current directory) is overwritten and so JVM can't find your class.
Add current directory to classpath, and everything works:
>java -cp C:\utils\groovy-1.8.1\embeddable\groovy-all-1.8.1.jar;. test
Hello, world
Upvotes: 18