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.
Asked
Active
Viewed 3,782 times
2
-
Have you checked the classpath for the execution ? – Bhavik Ambani May 24 '12 at 04:08
-
1You're trying to *replace* an XML file that is stored *inside* the very same JAR file that you're executing? – jamesmortensen May 24 '12 at 04:19
2 Answers
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