In Java, to execute a shell command, I would use something like this:

import java.io.*;
public class ExecuteCommand
{
   public static void main(String[] args)
   {
      try
      {
         Process proc = Runtime.getRuntime().exec("set" );
         BufferedReader result = new BufferedReader(
         new InputStreamReader(proc.getInputStream()));
         String line;
         while((line = result.readLine()) != null)
         {
            System.out.println(line);
         }
      }
      catch(IOException ex)
      {
         ex.printStackTrace();
      }
   }
}

The same thing can be done in Groovy with the following one-liner:

println "set".execute().text