Running Groovy

We have two options for running Groovy code. First, we can use the groovy command on our source code. Then Groovy automatically compiles code in memory and executes it. We don’t have to take an explicit step to compile it.

Second, if we want to take a more traditional Javalike approach of explicitly compiling code to create bytecode—the .class file—we can do that using the groovyc compiler. To execute the bytecode, we’ll use the java command just like we would to execute our compiled Java code. The only difference is that we need to have the groovy-all-2.1.0.jar file in the classpath. Remember to add a dot (.) to the classpath so java can find your classes in the current directory. This Java archive (JAR) is located in the ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.