<document>
<header>
<product>resin</product>
<title>Groovy</title>
<description>

<p>
Groovy is an agile, dynamic programming language that compiles source files
directly to java bytecode.  Groovy has a syntax similar to Java and includes
features found in Python, Ruby, and Smalltalk.  
</p>

See also:
<ul>
<li><a href="http://groovy.codehaus.org/">Groovy homepage</a>
<li><a href="http://dist.codehaus.org/groovy/distributions/">Groovy download</a>
<li><a href="http://www.jcp.org/en/jsr/detail?id=241">JSR 241: The Groovy Programming Language</a>
</ul>
</description>
</header>

<body>
<summary/>

<section title="Installing Groovy">

<p>
Install the groovy*.jar and asm*.jar files from the Groovy distribution in
the directory <code>$RESIN_HOME/lib/groovy/</code>:
</p>

<example title="$RESIN_HOME/lib/groovy">
$RESIN_HOME/lib/groovy/groovy-1.0-beta-4.jar
$RESIN_HOME/lib/groovy/asm-1.4.1.jar
$RESIN_HOME/lib/groovy/asm-attrs-1.4.1.jar
$RESIN_HOME/lib/groovy/asm-util-1.4.1.jar
</example>

<p>
The Groovy compiler <code>groovyc</code> compiles <code>*.groovy</code> files
directly to <code>*.class</code> files.  With Resin classloader configuration
.groovy files are automatically compiled the same as .java files are:
</p>

<example title="resin.conf - Groovy for all web-app's">
  &lt;web-app-default&gt;
     &lt;class-loader&gt;
       &lt;compiling-loader path="WEB-INF/classes"
                         compiler="groovyc"
                         source-extension=".groovy"/&gt;
      &lt;/class-loader&gt;
  &lt;/web-app-default&gt;
</example>

<example title="web.xml - Groovy for one web-app">
  &lt;web-app&gt;
     &lt;class-loader&gt;
       &lt;compiling-loader path="WEB-INF/classes"
                         compiler="groovyc"
                         source-extension=".groovy"/&gt;
      &lt;/class-loader&gt;
  &lt;/web-app&gt;
</example>

</section>

<section title="A Groovy Servlet">

<p>Since Groovy compiles to Java .class files, application can write
servlets using groovy.</p>

<example title="WEB-INF/classes/example/MyServlet.groovy">
package example;

import javax.servlet.GenericServlet;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyServlet extends GenericServlet {
  public void service(ServletRequest req, ServletResponse res)
  {
    out = res.getWriter();

    out.println("Hello, world");
  }
}

</example>

</section>

</body>
</document>
