title: How to save java source code in an xml file, and edit/compile it in an IDE?
body: <p>We have an java application in which the user can write/execute their own java code and use imports from compiled jars - i.e. they write it, and it is compiled and run by the application. They can also save this code (along with various other information that they are using) - currently this is saved to a human-readable xml file.</p>
  
  <p>I want to be able to use those save xml files in an IDE (principally, Intellij), so that if the user changes things in their compiled jar in the IDE, these changes can also be picked up in the save xml file.</p>
  
  <p>For example, if a save file used a class from the compiled jar, it may have the following import:</p>
  
  <pre><code>import com.company.project.package.subpackage.MyClass;
  </code></pre>
  
  <p>Let's say that class was moved, so the import was:</p>
  
  <pre><code>import com.company.project.package.subpackage.subsub.MyClass;
  </code></pre>
  
  <p>...this would change all the save xml files that used that class and import - just as the IDE would for all the other usages in the compiled project. </p>
  
  <p>(This, and other examples, arises because the compiled jar is both constantly in development and in use using the aforementioned application.)</p>
  
  <p>At the moment, if I were to add the save xml files to a sub-project in the IDE, the user can edit the save files manually, possibly taking advantage of 'find/replace' or 'search for usage in text' functions. This is better than nothing, but still a rather involved/complicated process. Also, there is no checking that the code in the save files are consistent with the code in the compiled project.</p>
  
  <p>One approach that I am considering is a script or a test class that would unpack the save xml file, writing the java code to java files, and then try and compile (and possibly running/testing) those java files. </p>
  
  <p>A further step would be to write a maven plugin (we use maven for our build cycle) or an ant script (ant still has its uses...) to do this, and possibly make this part of our build process - i.e. you cannot compile the project without ensuring all of the save xml files in its sub-project also compile.</p>
  
  <ul>
  <li>Does this seem like a reasonable approach?</li>
  <li>Are there alternative approaches that anyone could suggest?</li>
  </ul>