Skip to content
Advertisement

Modifying a file inside a jar

I would like to modify a file inside my jar. Is it possible to do this without extracting and re jarring, from within my application?

File i want to modify are configuration files, mostly xml based.

The reason i am interested in not un jarring is that the application is wrapped with launch4j if i unjar it i can’t create the .exe file again.

Advertisement

Answer

You can use the u option for jar

From the Java Tutorials:

jar uf jar-file input-file(s)

“Any files already in the archive having the same pathname as a file being added will be overwritten.”

See Updating a JAR File.

Much better than making the whole jar all over again. Invoking this from within your program sounds possible too. Try Running Command Line in Java

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement