Reputation: 7491
There is a command jar –uf (https://docs.oracle.com/javase/tutorial/deployment/jar/update.html) but by my observation it allows to add a class file only to the head directory of a jar. Otherwise, I need to unpack a jar, change a class file then pack again. Is there any more elegant way?
Upvotes: 0
Views: 83
Reputation: 8783
I corroborate Davide Lorenzo's right comment: Usually it is not a good practice to replace a class in an existing jar, but if you must absolutely do it, you can use the command-line utility jar
:
jar uf my.jar -C myclasses foo/bar/MyClass.class
... where myclasses
stands for the root directory for the complete subtree of all the *.class files.
Upvotes: 0
Reputation: 26926
A jar is simply a zip. So you can open it with a standard zip client (winzip, 7zip, winrar...) and add or remove all classes (that are normal files with extension .class) you like.
But why you need to change a class in an existing library? This normally is not a good procedure. If you are the owner of the library simply rebuilt it. If you aren't changing an existing class can create unexpected errors if you don't know exactly the interactions between existing classes.
Upvotes: 1