Is there are way to patch jar files?
Solution 1
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
Solution 2
There is JARDiff, designed for updating Java WebStart applications.
Solution 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.
GC_
Updated on December 18, 2020Comments
-
GC_ over 3 years
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?
-
Bryan Kyle about 13 yearsyes, jar files are just zip files, however there is a jar utility that you can use for this. It's part of the standard JDK.
-
GC_ about 13 yearsI mean does unjar/jar do anything special beyond unzip/zip?
-
casablanca about 13 years+1, this will usually work, however beware of modifying signed JARs in this way.
-
Bryan Kyle about 13 yearsI believe it will create a manifest for you if you don't already have one.
-
GC_ about 13 yearsWhen you say simply zip file, I have some doubts. It is my understanding that jarfiles also have a manifest.
-
Jeremy about 13 years@Grae - Sure, but how does that change the fact that the compression is the same as zip? Either way, that piece of information is probably irrelevant to the question so I am going to remove it.
-
GC_ about 13 yearsEven if I only had to change one jar file at a time, that would sill not help me in my particular case, because all of the jar files are in one war file.
-
Paŭlo Ebermann about 13 years@Grae: It depends what is in the manifest file. Often it contains nothing which would differ from one to next version of jar. If it contains signing information, you would have to change this, too. Simply create one jar with the old and new class as you would normally and compare the manifest files to see if this would matter for you.
-
GC_ about 13 yearsjar umf foo.jar foo.class - I found this on the link. I think this is the best choice.
-
Jeremy S over 9 yearsFYI, the link in the answer no longer works. This seems to be the same article: docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html