Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying a file inside a jar

Tags:

java

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.

like image 263
Hamza Yerlikaya Avatar asked Aug 03 '09 21:08

Hamza Yerlikaya


People also ask

Is it possible to edit a JAR file?

You can use the JAR file editor to view or edit JAR file information that is stored in a data development project. If you make changes to JAR file information using the editor, you must deploy the JAR file to the database server again to apply the changes to the server version of the JAR file.

How do I edit a manifest in a JAR file?

To modify the manifest, you must first prepare a text file containing the information you wish to add to the manifest. You then use the Jar tool's m option to add the information in your file to the manifest. Warning: The text file from which you are creating the manifest must end with a new line or carriage return.


1 Answers

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

like image 96
clwhisk Avatar answered Oct 15 '22 21:10

clwhisk