Sunday, August 1, 2010

GRAPE

GRAPE, the 'Groovy Adaptable Packaging Engine' allows an application's dependencies to be specified in the code or as arguments on the command line and, at runtime, the dependencies will be downloaded and added to the application's classloader.

An example of Groovy, Hibernate (not GORM), HSQL and SLF4J.

The following example is from the GRAPE homepage.

import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.*
import groovy.servlet.*

@Grab(group = 'org.mortbay.jetty', module = 'jetty-embedded', version = '6.1.0')
def runServer(duration) {
    def server = new Server(8080)
    def context = new Context(server, "/", Context.SESSIONS);
    context.resourceBase = "."
    context.addServlet(TemplateServlet, "*.gsp")
    server.start()
    sleep duration
    server.stop()
}

runServer(10000)