有没有办法给jar文件打补丁?
假设我向某人发送了一个大 jar 或 war 文件。我可以稍后只更改一小部分并将其发送给他吗?假设我刚刚更改了一个类文件。我将java重新编译成类文件。除此之外,将新的类文件交换为旧的类文件,我还需要做什么吗?
在java中你必须重建整个jar/war文件吗?另外,是否有一些开源包可用于进行更新?
Suppose I sent a large jar or war file to someone. Could I later just change one small section and send that to him? Suppose I just changed one class file. I recompiled the java for into a class file. Other then exchanging the new class file for the old class file it there anything else I would have to do?
In java do you have to rebuild the entire jar/war file? Also, is there some open source package available for doing updates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
接收类文件的人可以简单地将该文件添加到 jar 中,只要他们知道将其放入哪个目录即可。如注释中所述,请厌倦签名的 jar。
http://docs.oracle.com/javase/7 /docs/technotes/tools/solaris/jar.html
The person receiving the class file could simply add that file to the jar as long as they know which directory to put it in. Be weary of signed jars, as noted in the comments.
http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html
您可以通过这种方式复制修改后的.class 文件。
如果有一种逻辑方法可以让您将组件分离到各个 jar 文件中,那么我会为每个组件类型创建一个 jar 文件。这样您就不必将所有内容重新分发回客户端。例如 - 看一下 Spring 3 如何分离出组件。
You can copy the modified .class file this way.
If there is a logical way for you to separate out your components in individual jar files then I would create a jar file per component type. That way you will not have re-distribute everything back to the client. For example - take a look at how Spring 3 has the components separated out.
JARDiff 是专为更新 Java WebStart 应用程序而设计的。
There is JARDiff, designed for updating Java WebStart applications.
您将需要重建整个 jar 文件,除非您希望它们解压缩、覆盖文件并重新 jar。
You will need to rebuild the entire jar file unless you want them to unjar, overwrite a file and rejar.
看一下
jar
命令的用法。选项 u 允许您更新现有存档。Take a look at the usage of
jar
command. The option u lets you update an existing archive.只需使用 7zip 打开您的 jar 文件并覆盖您编辑的类即可。不过,请务必先进行备份。
Just open up your jar file with 7zip and overwrite the classes you have edited. Make sure to make a backup first though.
如果您有旧的和新的 jar 文件,您可以创建两者的 xdelta 并仅发送如果您只更改了许多类中的一类,则该 delta 文件应该比整个 jar 文件小得多。这也适用于签名的 jar,但要求发送者和接收者都具有 xdelta 程序(或能够安装它)。
当然,您必须首先创建新的 jar (但这可以通过其他答案已经提到的方法来完成)。
If you have your old and new jar file, you can create an xdelta of both and send only the delta file to your client, which should be much smaller than the whole jar file, if you changed only one class of many. This should work for signed jars, too, but requires that both sender and receiver have the xdelta program (or be able to install it).
And of course, you have to create the new jar first (but this can be done by the methods already mentioned by the other answers).