When I did which groovy
, I got the below output:
/usr/local/bin/groovy
So I went ahead and created a helloworld.groovy
with the below content
#!/usr/local/bin/groovy println "hello world"
After that I did chmod +x helloworld.groovy
and attempted to run the file with ./hellworld.groovy
and sadly, I got this error ./helloworld.groovy: line 2: print: command not found
I could get rid of the error by changing to
#!/usr/bin/env groovy println "hello world"
Why would the first method cause the error?
Test a Groovy application You can test Groovy applications using JUnit 4 and JUnit 5 testing frameworks. Open a class in the editor, for which you want to create a test and place the cursor within the line containing the class declaration. Press Ctrl+Shift+T and select Create New Test.
You need to run the script like this:
groovy helloworld.groovy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With