Modify Executing Jar file

Posted by pinkynobrain on Stack Overflow See other posts from Stack Overflow or by pinkynobrain
Published on 2010-03-17T15:58:39Z Indexed on 2010/03/17 16:01 UTC
Read the original article Hit count: 370

Filed under:
|
|
|
|

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.

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.

The following are three approaches i can see to solving the problem, feel free to comment on them or suggest others.

  1. Tell Java to unlock the JAR file for writing(this doesnt seem possible but it would be the easyest solution)
  2. 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)
  3. Put a Second executable JAR File inside the First, on startup extract the inner jar to e temporaryfile, invoke a new java process 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)

I know this is a weird question but any help would be appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about jar