有没有办法给jar文件打补丁?

发布于 2024-10-18 10:46:47 字数 164 浏览 3 评论 0原文

假设我向某人发送了一个大 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

素罗衫 2024-10-25 10:46:47

接收类文件的人可以简单地将该文件添加到 jar 中,只要他们知道将其放入哪个目录即可。如注释中所述,请厌倦签名的 jar。

jar uf foo.jar foo.class

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.

jar uf foo.jar foo.class

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html

心凉怎暖 2024-10-25 10:46:47

您可以通过这种方式复制修改后的.class 文件。

jar uf test.jar com\test\Test.class

如果有一种逻辑方法可以让您将组件分离到各个 jar 文件中,那么我会为每个组件类型创建一个 jar 文件。这样您就不必将所有内容重新分发回客户端。例如 - 看一下 Spring 3 如何分离出组件。

You can copy the modified .class file this way.

jar uf test.jar com\test\Test.class

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.

南风几经秋 2024-10-25 10:46:47

JARDiff 是专为更新 Java WebStart 应用程序而设计的。

There is JARDiff, designed for updating Java WebStart applications.

同展鸳鸯锦 2024-10-25 10:46:47

您将需要重建整个 jar 文件,除非您希望它们解压缩、覆盖文件并重新 jar。

You will need to rebuild the entire jar file unless you want them to unjar, overwrite a file and rejar.

寄离 2024-10-25 10:46:47

看一下jar命令的用法。选项 u 允许您更新现有存档。

Take a look at the usage of jar command. The option u lets you update an existing archive.

月光色 2024-10-25 10:46:47

只需使用 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.

梦晓ヶ微光ヅ倾城 2024-10-25 10:46:47

如果您有旧的和新的 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文