Is it possible to create or modify files inside jar and if it is how to accomplish that?
-
1A JAR is only an archive, so it is possible. You want to do this in the application itself or by hand? – tbraun89 Sep 04 '12 at 21:05
-
1Why do you want to modify something inside jar? – Roman C Sep 04 '12 at 21:20
4 Answers
One possible solution is to unzip the jar
, modify it and zip it back up.
NOTE: You can extract it with a utility like 7-zip or WinRar.

- 5,113
- 1
- 27
- 38
In a word, yes its possible and you have several options:
Modify the existing jar file. Do this by extracting the jar file (use whatever extractor you need to), modify the file you want (decompile if you don't have the source) and then repackage the jar.
If you don't want to go thru the trouble of changing the jar, you want to copy the existing class file (again decompile if you don't have the source), make the changes you want, compile it and make sure your class file is ahead of the jar in your CLASSPATH. That way when your VM does its classloading, it'll get your modified class first and ignore the one in the jar.

- 2,624
- 2
- 19
- 16