Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Getting Started

wmacgyver edited this page · 4 revisions
Clone this wiki locally

Getting Started

Here is the simplest example of a Gretty web application. All you need is to have Groovy 1.8.0 installed.

import org.mbte.gretty.httpserver.* 

@GrabResolver(name='gretty', root='') 

GrettyServer server = [] 
server.groovy = [ 
    localAddress: new InetSocketAddress("localhost", 8080), 
    static: "static", 
    defaultHandler: { 
        response.redirect "/" 
    "/": { 
        get { 
            response.html = 'hi' 

Using @Grab, Groovy will automatically download all the necessary jars, and start the server for you. We set the server to run at port 8080. We set Gretty to serve static content out of the static directory.

There are two routes setup. "/" to match top level, and only handles GET request.

The other route "default", handles all non matching routes.

Make sure you have the static directory created, or you'll get an error.

Something went wrong with that request. Please try again.