I am currently struggling with installation/getting started with Groovy.
With a file called Hello.groovy
I have written:
println "Hello, Groovy!"
When I use groovyc Hello.groovy
to create the class file, the compilation works. However, when I try to run the class file using groovy Hello.class
I get the following error:
“
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/Users/lukemccartney/Desktop/apache-groovy-course/getting-started/groovyc/Hello.class: 1: Unexpected character: ‘�’ @ line 1, column 1.
����@YHellogroovy/lang/Script
Hello.groovy$staticClassInfo*Lorg/codehaus/groovy/reflection/ClassInfo;__$stMCZ()V
^
1 error
“
I tried installing groovy via sudo apt-get install groovy
on my Ubuntu VM and I get the same problem when I run groovyc Hello.groovy
and groovy Hello.class
.
2
Answers
dagget's response the answer above works flawlessly and is exactly what I was looking for. As far as I am aware,
groovy
does not create jar files.The
groovy
cli app runs groovy scriptsThe
groovyc
cli app compiles groovy scripts to JVM bytecodeYou can’t run JVM bytecode directly with the
groovy
cli app.To run it, use the
java
command: