tags:

views:

46

answers:

2

Hi people,

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?:)

A: 

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.

Yoni
A: 

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

Colin Hebert
Hm, than i should at first create a JarFile file:/Users/admin/.m2/repository/code/1.1-SNAPSHOT/code-1.1-SNAPSHOT.jar and then getEntity /META-INF/config.js from this jar file, right?
Le_Coeur
You don't have to create anything, you open the jar with `new JarFile(pathToJar)` and then you `getEntry(yourFile)`.
Colin Hebert
And than, what can i do with this entry? How can i write in it?
Le_Coeur