Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there are way to patch jar files?

Tags:

java

patch

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?

like image 441
GC_ Avatar asked Feb 21 '11 18:02

GC_


2 Answers

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

like image 152
Jeremy Avatar answered Oct 06 '22 17:10

Jeremy


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.

like image 36
CoolBeans Avatar answered Oct 06 '22 16:10

CoolBeans