Modify Executing Jar file

蹲街弑〆低调 提交于 2019-11-30 19:10:18

One option:

Have the program write a modified copy of the JAR file.

Include in the JAR file a second JAR with a utility that, when executed, deletes the original JAR file and renames the modified copy to match that of the original.

When your program exits (and changes have been made) extract this utility and launch it in its own JVM (using Runtime.getRuntime().exec()). The utility would wait for the lock to go off the original, unmodified JAR and then do its business and exit.

To the user the JAR file would seem to update on exit (or close enough!).

I honestly think your approach is wrong headed. This is simply not a good fit to the default way of deploying java. Your modified files will just have to persist to a db or xml file somewhere - that is the ONLY sensible approach.

Anything is just "fighting against the wind" - you might with some struggling get it to work, but it WILL bite you or customer eventually.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!