2

Im am trying to replace a XML file while executing the JAR File. But Currently It comes with with an Java IO File not Found Exception. But i doubled Check the Path and it is correct. I am wondering if it is possible to replace a xml file within an jar file. If so how is it done. Thank you.

animuson
  • 53,861
  • 28
  • 137
  • 147
user1414056
  • 41
  • 2
  • 5

2 Answers2

5

yes you can do that. Make dir where you want to try the below commands. Go to that dir and try:

>cd <to_your_dir>
>jar -xvf <jar_file_path_with_name>

This will extract the jar out. Change the file that you want to change and jar it back:

>jar -cvf <out_jar_file_name> *

Make sure you are running this from with in the folder where you extracted the jar. you can verify the contents structure by running below command on both the jars:

>jar -tvf <jar_file_name>
havexz
  • 9,550
  • 2
  • 33
  • 29
2

The easiest way to do it is this:

# Find the file inside the jar
jar tvf <JarFile> | grep xml | less

# Extract your file
jar xvf <JarFile> <FilePath> 

# Edit your file

# Replace updated file in your jar
jar uvf <JarFile> <UpdatedFileWithSameName>
Debajit
  • 46,327
  • 33
  • 91
  • 100