如何修补Java程序? [英] How to patch a Java program?
问题描述
最近我将修复程序应用于Java桌面应用程序。我这样做是通过更改我的一个类中的代码,编译它并将新jar发送到生产环境。
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.
我现在被问到是否可以通过复制我修复的编译类来修改生产中的jar,甚至创建一个修补程序/脚本只能更新修改后的文件。
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.
其他信息:
- 补丁不必在运行时应用。这意味着补丁可以作为单独的程序或活动来完成。我的旧程序不需要自动更新。
- 这可以通过Web应用程序(WAR文件)完成吗?
我提出的最佳答案就是这个,但它已经有2年了。
修补Java软件
The best answer I came up is this, but it's 2 years old. Patching Java software
我的要求很少吗?我从未见过修补Java应用程序的教程。
Is my requirement rare? I have never seen a tutorial to patch a Java application.
推荐答案
我现在被问到是否可以通过复制我修复的编译类来修改生产中的jar,甚至可以创建一个只能更新修改过的文件的修补程序/脚本。
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.
是的。可以使用 jar -u
修补JAR文件。也可以用相同的方式修补WAR文件。
Yes. It is possible to patch a JAR file using jar -u
. It is also possible to patch a WAR file the same way.
但我不推荐它。 JAR或WAR文件应该是部署/管理的单位。如果您开始在生产服务器上修补JAR / WAR文件,则很难跟踪实际使用的位置。如果你不小心,混乱和混乱将统治。
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.
唯一的情况是修补是不可避免的,你有第三方图书馆或你不能的东西从源代码构建,但你需要修改。但即使在这种情况下,最好在构建平台上修改JAR / WAR并部署修改后的JAR / WAR。尝试在生产平台上修补JAR,WAR或部署的webapp是一个坏主意。
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 ...
我从未见过修补Java应用程序的教程。
I have never seen a tutorial to patch a Java application.
这并不奇怪,因为有更好的方法......
Not surprising, given that there's a better way ...
这篇关于如何修补Java程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!