title: A Java API to generate Java source files
body: <p>I'm looking for a framework to generate Java source files.</p>
  
  <p>Something like the following API:</p>
  
  <pre><code>X clazz = Something.createClass("package name", "class name");
  clazz.addSuperInterface("interface name");
  clazz.addMethod("method name", returnType, argumentTypes, ...);
  
  File targetDir = ...;
  clazz.generate(targetDir);
  </code></pre>
  
  <p>Then, a java source file should be found in a sub-directory of the target directory.</p>
  
  <p>Does anyone know such a framework?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>:</p>
  
  <ol>
  <li>I really need the source files.</li>
  <li>I also would like to fill out the code of the methods.</li>
  <li>I'm looking for a high-level abstraction, not direct bytecode manipulation/generation.</li>
  <li>I also need the "structure of the class" in a tree of objects.</li>
  <li>The problem domain is general: to generate a large amount of very different classes, without a "common structure".</li>
  </ol>
  
  <hr>
  
  <p><strong>SOLUTIONS</strong><br>
  I have posted 2 answers based in your answers... <a href="https://stackoverflow.com/questions/121324/a-java-api-to-generate-java-source-files#136010">with CodeModel</a> and <a href="https://stackoverflow.com/questions/121324/a-java-api-to-generate-java-source-files#136016">with Eclipse JDT</a>.</p>
  
  <p>I have used <a href="http://codemodel.java.net/" rel="noreferrer">CodeModel</a> in my solution, :-)</p>