Search code examples
groovyratpack

Start ratpack.groovy from Java


I´m trying to use ratpack groovy framework from Java, but I cannot find a way to init from Java.

Any idea how to start up a ratpack.groovy script from Java?

This is my ratpack script

 ratpack {
def tokens=[:]
serverConfig {
    port 9000
}
handlers {
    get("identity/:token") {
        def token= pathTokens["token"]
        render tokens[token]
    }
}
}

Regards.


Solution

  • Based on GroovyRatpackMain, you can start a Groovy app from Java like this:

    import ratpack.server.RatpackServer;
    
    RatpackServer.start(Groovy.Script.appWithArgs(args));
    

    If you need to use a non-default script file or perform other customization, Groovy.Script has methods to support that.