I am building an update system in which I need to be able to replace a referenced jar of a running application jar at runtime. However, I am running into file locking issues on Windows when trying to perform file utility functions on the jar such as 'setLastModified'.
After some googling I found this snippet...
What I found in my research is that the standard ClassLoader implementation never closes a jar file once it has been opened. It also only loads resources from the jar file as needed. So at any particular time, there may be Classes in the jar file that have not been loaded into memory. Obviously, if you delete the jar file out from under the ClassLoader, and it tries to find a resource in the missing file, you're going to get an IOException at the very least.
Does anyone have any references to information on doing this, or working around this issue?
Thanks.
If graphical apps are an option, you could use winrar or 7-zip to replace the class. You don't need to extract the jar file to make this work. Just open the jar with one of those apps, go to de directory where is the class file to be replaced, drag-and-drop the new file to replace the old one and save.
Right-click on the JAR file. Go to “Open With Other Applications”. Select Show other applications. Select Open With OpenJDK Java X Runtime.
You can use the JAR file editor to view or edit JAR file information that is stored in a data development project. If you make changes to JAR file information using the editor, you must deploy the JAR file to the database server again to apply the changes to the server version of the JAR file.
There is a lot of solutions for classes/lib hot-swapping :
It depends on what you want to do.
The closest thing is OSGi
Please have a look at the 'See also' section of the mentioned artice for concrete products.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With