Modifying a file inside a jar
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
How can I modify a text file inside a Jar file while runtime?
You can't change any content of a jar which is currently used by a jvm. This file is considered locked by the operating system and therefore can't be changed.
I suggest to write this file outside your jar file. e.g. in a /conf
directory relative to the current working dir.
Modify information inside jar file
I would recommend having an external text file stored somewhere relative to your program. Then have your program modify it as it needs.
How do I update one file in a jar without repackaging the whole jar?
-C
is changing the local directory, and is looking for hi.png
there. It's not controlling where you're trying to inject it into the JAR file.
I would try making a new directory called images
, moving your local hi.png
into that, making images
a child directory of your current working directory, then just run this:
jar uf myfile.jar images\hi.png
Edit the .properties file inside a jar without extracting it or changed to .zip format
JAR files are built on the ZIP file format and have the .jar file extension. you can create or extract JAR files using the jar command that comes with a JDK. You can also use zip tools to do so;
You have to know that JAR files - like any other ZIP files is in compressed format. You cannot update a file inside a zip archive without extracting it and putting it back to the archive,no matter what tool may you use (Zip,WinRar,7-Zip or jar) you are just extracting the file and editing and then putting it back to the archive.The below given answers are also doing that,but the file are being extracted to a temporary directory and you are not seeing it.
Related Topics
How to Enumerate All Classes in a Package and Add Them to a List
Why Does List<String>.Toarray() Return Object[] and Not String[]? How to Work Around This
Mockito: Trying to Spy on Method Is Calling the Original Method
Adding Up Bigdecimals Using Streams
How to Find Out the Currently Logged-In User in Spring Boot
Retrieving a Random Item from Arraylist
Select an Option from the Right-Click Menu in Selenium Webdriver - Java
How to Create a Topic in Kafka from the Ide Using API
Java; String Replace (Using Regular Expressions)
Convert Base64 String to Image
Date Format Parse Exception - "Eee Mmm Dd Hh:Mm:Ss Z Yyyy"
Run Main Class of Maven Project
How to Print Line Numbers to the Log in Java
Stand-Alone Java Code Formatter/Beautifier/Pretty Printer
How to Format a String in an Email So Outlook Will Print the Line Breaks