Reputation: 41
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.
Upvotes: 2
Views: 4119
Reputation: 47111
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>
Upvotes: 2
Reputation: 9590
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>
Upvotes: 5