Reputation: 1541
so, i have a jar file and in this jar there is another config.js file, and in this file i want to write. I have a Resource class of this file (org.springframework.core.io.Resource), so i can get a full URL or getFile() from this Resource. URL look's like this:
jar:file:/Users/admin/.m2/repository/code/1.1-SNAPSHOT/code-1.1-SNAPSHOT.jar!/META-INF/config.js
The porblem is, if i try to getFile() from Resource i get an Exception : cannot be resolved to absolute file path because it does not reside in the file system. So how can i write to this file in jar?:)
Upvotes: 0
Views: 1274
Reputation: 10321
Use the api in java.util.zip
and java.util.jar
.
If I recall correctly, you can modify the file "inline" and save, or just modify it outside, save to a temp file, and then push the temp file back into the jar.
Upvotes: 0
Reputation: 93197
You can use ZipStreams on your jar, and from there you can handle your jar.
The best way to handle your jar directly is to use ZipFile
or even better JarFile
Upvotes: 1