How to replace a file in a JAR file – Java Archive

While the answer seems to be very elusive it appears to be quite simple. The java jar tool is required (part of the jdk I believe) and it can be used like this:

jar uf myJarFile.jar com\vsoft\servlet\myServlet.class

This will replace the class myServlet.class inside the myJarFile.jar with a new one located in com\vsoft\servlet\myServlet.class

You may open the jar in winzip / 7zip to see that it in fact replaced the class with a new date/time. If you do not properly match the full path of the original class within the original jarfile it will ADD the class into the jar instead of replacing the original class so be sure to properly create the full path to the updated class.

I stumbled across some helpful info from here which was the basis for this posting.

2 Responses to How to replace a file in a JAR file – Java Archive

  1. Pingback:How To Replace a File in a Jar File – Java Archive

  2. thnx… 7-zip is more easy to use this editing…