Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fix links

...

There is an Ant task called groovyc which works pretty similarly to the javac Ant task which takes a bunch of groovy source files and compiles them into Java bytecode. Each groovy class then just becomes a normal Java class you can use inside your Java code if you wish.
Indeed the generated Java class is indistinguishable from a normal Java class, other than it implements the
linkGroovyObjectGroovyObject1apidocs/groovy/lang/GroovyObject.html  
GroovyObject interface.

Compiling Groovy code to bytecode using Ant and Maven

The groovyc Ant task is implemented by the
linkGroovycGroovyc1apidocs/org/codehaus/groovy/ant/Groovyc.html class. You can see an example of this in action inside Groovy's maven.xml file (just search for 'groovyc')

There is also an excellent
link article on DeveloperWorks
article on DeveloperWorks1http://www-128.ibm.com/developerworks/java/library/j-pg11094/ which will show you how to compile Groovy code from within Maven, similarly to what is done with Ant.

You can also use the Ant task
linkfrom within Maven2from within Maven21/display/GROOVY/Compiling+With+Maven2,
or the
link groovy-maven-plugin groovy-maven-plugin1http://mojo.codehaus.org/groovy/

Dynamically using Groovy inside Java applications

If you don't want to explicitly compile groovy code to bytecode you can just
linkembed groovyembed groovy1Embedding+Groovy directly into your Java application.

Runtime dependencies

As well as Java 1.4, or above, and the Groovy jar we also depend at runtime on the ASM library (asm and asm-tree mainly), as well as Antlr. You can also use the groovy-all-xxx.jar from your GROOVY_HOME/embeddable directory, which embeds ASM and Antlr in its own namespace, to avoid Jar version hell.