title: Basic Groovy Script Engine Setup
body: <p>Background (can skip): </p>
  
  <p>I recently wrote a lightweight server in Java that polls for new connections on a port, and then when a client connects it gives them their own thread until the socket closes. Now, what I need to do once a client is connected is prepare for XML file requests in a special way; If a client requests file1.xml, the server needs to read in file1.xml, parse it to JSON, and send the json object to the client. </p>
  
  <p>Problem Specific (now start reading): 
  I need to parse XML files into JSON objects in Java. I was recommended GROOVY for this task. It was a breeze to install on both my mac and ubuntu partitions, but I cannot get inline groovy working, and the reason is most likely very trivial. Here's what I'm testing now (at this point, I'm just trying to get embedded groovy working): </p>
  
  <p><strong>test.groovy</strong></p>
  
  <pre><code>output = "Hello ${input}!" 
  </code></pre>
  
  <p><strong>test.java</strong></p>
  
  <pre><code>import groovy.lang.Binding; 
  import groovy.util.GroovyScriptEngine; 
  
  String[] roots = new String[] { "/home/nick/Documents" }; 
  GroovyScriptEngine gse = new GroovyScriptEngine(roots); 
  Binding binding = new Binding(); 
  binding.setVariable("input", "world"); 
  gse.run("test.groovy", binding); 
  System.out.println(binding.getVariable("output")); 
  </code></pre>
  
  <p>Both of these files are in my <code>/home/nick/Documents</code> folder. When I try to compile with: </p>
  
  <pre><code>javac test.java 
  </code></pre>
  
  <p>I get 6 errors: </p>
  
  <pre><code>test.java:4: class, interface, or enum expected 
  String[] roots = new String[] { "/home/nick/Documents" }; 
  ^ 
  test.java:5: class, interface, or enum expected 
  GroovyScriptEngine gse = new GroovyScriptEngine(roots); 
  ^ 
  test.java:6: class, interface, or enum expected 
  Binding binding = new Binding(); 
  ^ 
  test.java:7: class, interface, or enum expected 
  binding.setVariable("input", "world"); 
  ^ 
  test.java:8: class, interface, or enum expected 
  gse.run("test.groovy", binding); 
  ^ 
  test.java:9: class, interface, or enum expected 
  System.out.println(binding.getVariable("output")); 
  ^ 
  6 errors 
  </code></pre>
  
  <p>I feel I'm doing something wrong at the compile stage. How can I get this compiling and running? </p>
  
  <p>Help very much appreciated</p>