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.

About the Author

Hello, my name is Mark Vejvoda. I am first and foremost a born again child of God. My life revolves around Jesus Christ, He is the center of my universe. With that said and established, outside of being a Christian, it is necessary to live in a world that is certainly not Christian. Is this diary / blog you see a view on life from the perspective of a Jesus Lover, and perhaps some side effects of that relationship as I interact with the rest of the world. [gallery=1]

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

  1. […] 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 comvsoftservletmyServlet.class …Continue Reading… […]

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