Groovy

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
(New page: See also: * [http://groovy.codehaus.org/ Groovy homepage] * [http://dist.codehaus.org/groovy/distributions/ Groovy download] * [http://www.jcp.org/en/jsr/detail?id=241">JSR 241: The Groov...)
 
 
Line 3: Line 3:
 
* [http://groovy.codehaus.org/ Groovy homepage]
 
* [http://groovy.codehaus.org/ Groovy homepage]
 
* [http://dist.codehaus.org/groovy/distributions/ Groovy download]
 
* [http://dist.codehaus.org/groovy/distributions/ Groovy download]
* [http://www.jcp.org/en/jsr/detail?id=241">JSR 241: The Groovy Programming Language]
+
* [http://www.jcp.org/en/jsr/detail?id=241 JSR 241: The Groovy Programming Language]
  
 
== Installing Groovy ==
 
== Installing Groovy ==

Latest revision as of 17:50, 3 February 2008

See also:

Installing Groovy

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

$RESIN_HOME/ext-lib/groovy

$RESIN_HOME/ext-lib/groovy/groovy-1.0-beta-4.jar
$RESIN_HOME/ext-lib/groovy/asm-1.4.1.jar
$RESIN_HOME/ext-lib/groovy/asm-attrs-1.4.1.jar
$RESIN_HOME/ext-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-apps

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

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

Personal tools