Loading...

October 2, 2015

Ratpacked: Start Ratpack With a Random Port Number

To start our Ratpack application with a random port number we must use the value 0 as port number. The value 0 tells Ratpack to use a random port number (in a safe port range).

In the following example Ratpack application we configure the server port to be random:

import static ratpack.groovy.Groovy.ratpack

ratpack {
    serverConfig {
        // Tell Ratpack to use a 
        // random port number.
        port 0
    }
}

Written with Ratpack 1.0.0.