Groovy
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

IDE's
Scottit
Groovy
PHP
Code Libraries
EJB Servers
JMS
JCA Resources
JMX
SSL Accelerators
Scottit
Third-party
PHP

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.

See also:

  1. Installing Groovy
  2. A Groovy Servlet
  3. Caveat

Installing Groovy

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

$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

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

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

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

A Groovy Servlet

Since Groovy compiles to Java .class files, application can write servlets using groovy.

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");
  }
}

Caveat

At the time of this writing (groovy 1.0 beta-4) groovy has some issues with classloaders. See the Groovy bug report and vote on it to increase the chance that it will be fixed. Simple beans will work, but more complicated things like closures may not work at all times.


Scottit
Third-party
PHP
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.