title: Modify Executing Jar file
body: <p>Hello Stack Overflow friends.  I have a simple problem which i fear doesnt have a simple solution and i need advice as to how to proceed.  I am developing a java application packaged as and executable JAR but it requires to modify some of its JAR file contents during execution.  At this stage i hit a problem because some OS lock the file preventing writes to it. </p>
  
  <p>It is essential that the user sees an updated version of the jar file by the time the application exits allthough i can be pretty flexible as to how to achieve this.  A clean and efficient solution is obviously prefereable but portability is the only hard requirement.  </p>
  
  <p>The following are three approaches i can see to solving the problem, feel free to comment on them or suggest others.</p>
  
  <ol>
  <li>Tell Java to unlock the JAR file for writing(this doesnt seem possible but it would be the easyest solution)</li>
  <li>Copy the executable class files to a tempory file on application startup, use a class loader to load these files and unload the ones from the initial JAR file.(Not had much experience with the classloaders but hopefully the JVM would then be smart enough to realize that the original JAR is nolonger in use and so unlock it)</li>
  <li>Put a Second executable JAR File inside the First, on startup extract the inner jar to e temporaryfile,  invoke a new java process using the copyed inner JAR and pass it the location of the Outer JAR, first process exits, second process modifys the Outer jar unincumbered.(This will work but im not sure there is a platform independant way of one java app invoking another)</li>
  </ol>
  
  <p>I know this is a weird question but any help would be appreciated.</p>