title: extend Java class with groovy
body: <p>I have a java class (named A) that needs to be executed by groovy. This class is standalone. I want to dynamically extend it with the class B.</p>
  
  <p>The code for class A:</p>
  
  <pre><code>public class A {
      public void run() {
          System.out.println(context);
      }
  }
  </code></pre>
  
  <p>The code for class B:</p>
  
  <pre><code>public class B {
      protected String context;
  
      public void setContext(Context c) {
          this.context = c;
      }
  }
  </code></pre>
  
  <p>The code controlling groovy:</p>
  
  <pre><code>String code = FileUtils.readFileAsString(new File("A.java"));
  GroovyObject obj = new GroovyClassLoader().parseClass(code).newInstance();
  // here I want to make A extend B
  </code></pre>
  
  <p>I tried to use obj.setMetaClass but I don't find any example in Java.</p>
  
  <p>Can someone has already done this ?</p>