Groovy's GroovyShell Class

Another easy way to evaluate Groovy Dice scripts from a Java application is to use the Groovy's GroovyShell class:

import groovy.lang.*;
import net.sf.groovydice.*;

public class MyDiceRollerApp {
    static final GroovyShell shell;

    static {
        new GroovyDice().initialize();
        shell = new GoovyShell();
    }

    public static void main(String[] args) {
        System.out.println(shell.evaluate("5.d10 * -8"));
    }
}

For more information, please read the GroovyShell documentation.