0

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
Le_Coeur
  • 1,521
  • 5
  • 28
  • 44

2 Answers2

1

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
  • 91,525
  • 15
  • 160
  • 151
  • 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 Aug 23 '10 at 19:45
  • You don't have to create anything, you open the jar with `new JarFile(pathToJar)` and then you `getEntry(yourFile)`. – Colin Hebert Aug 23 '10 at 19:49
  • And than, what can i do with this entry? How can i write in it? – Le_Coeur Aug 23 '10 at 19:52
0

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
  • 10,171
  • 9
  • 55
  • 72