Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to patch a Java program?

Recently I applied a fix to a Java desktop application. I did this by changing the code in one of my classes, compiled it and sent the new jar to the production environment.

I'm now asked if it is possible to just patch the jar in production by just copying the compiled class that I fixed, or even create a patching program/script that will be able to update just the modified files.

Additional info:

  1. The patch does not have to be applied in run time. Meaning the patch can be done as a separate program or activity. My old program does not need to auto update itself.
  2. Can this be done with web applications (WAR file) too?

The best answer I came up is this, but it's 2 years old. Patching Java software

Is my requirement rare? I have never seen a tutorial to patch a Java application.

like image 452
Jefrey Valencia Avatar asked Jul 10 '13 00:07

Jefrey Valencia


2 Answers

I'm now asked if it is possible to just patch the jar in production by just copying the compiled class that I fixed, or even create a patching program/script that will be able to update just the modified files.

Yes. It is possible to patch a JAR file using jar -u. It is also possible to patch a WAR file the same way.

But I would NOT recommend it. The JAR or WAR file should be the unit of deployment / management. If you start patching JAR / WAR files on production servers, it is hard to track what is actually being used where. If you are not careful, chaos and confusion will reign.

The only situation where patching is unavoidable is where you have a 3rd-party library or something that you can't build from source, but you need to modify nevertheless. But even in that case it is best to modify the JAR / WAR on your build platform and deploy the modified JAR / WAR. Trying to patch JARs, WARs or deployed webapps on the production platform is a bad idea.


Is my requirement rare?

Yes. There's a better way ...

I have never seen a tutorial to patch a Java application.

Not surprising, given that there's a better way ...

like image 105
Stephen C Avatar answered Oct 23 '22 20:10

Stephen C


You can update the old jar by doing jar uf jarfile classfile(s)

This will replace old class files with same name with new ones, making an auto patcher using that should not be hard

like image 4
Epicblood Avatar answered Oct 23 '22 21:10

Epicblood