0

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.

paul
  • 12,873
  • 23
  • 91
  • 153
  • You want to use `RatpackServer.of`, an example of this is [here](http://asaf.github.io/blog/2015/02/15/ratpack_hello_world/) – Glen Jul 25 '16 at 16:26
  • Thanks but what I´m looking is how to use a ratpack.groovy from Java. I dont want to code in Java, it´s much more verbose – paul Jul 25 '16 at 16:32
  • Ah ok I missed that nuance, I would suggest then still using `RatpackServer` to initialize the server and then use a `GroovyChainAction` to define your handlers. – Glen Jul 25 '16 at 16:38
  • Do you know any place where I can take a look a code example to do that?, thank! – paul Jul 25 '16 at 16:43
  • Probably the most concise example is in the [javadoc](https://ratpack.io/manual/current/api/ratpack/groovy/handling/GroovyChainAction.html) – Glen Jul 25 '16 at 16:56

1 Answers1

2

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.

davidmc24
  • 2,232
  • 1
  • 19
  • 17