skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. The groovy cli app runs groovy scripts

    The groovyc cli app compiles groovy scripts to JVM bytecode

    You can’t run JVM bytecode directly with the groovy cli app.

    To run it, use the java command:

    java -cp ~/path/to/groovy/lib/groovy-4.0.11.jar:. Hello
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search