Forums Register Login

Jar files. Urgent Please Reply

+Pie Number of slices to send: Send
Hello all !!
I have written an application that's contained in a jar. The application needs to access a properties file in the jar,which it does with no problem, modify the file, and then save it back to the jar.
The problem that I am getting is that each time a save the file to the jar, it creates a brand new jar with the same name as the one I had, and therefore I loose all my .class files and manifest.
I've been trying to get round this for hours now, but I am getting nowhere I'm starting to beleive that you can't save a file to an existing jar (without loosing the jar's content) unless you extract the existing files and then create a new jar with all the old files plus the new ones. Please someone tell me I don't need to do so, it would be very ugly.
If someone would be kind enough to answer my question I would be much obliged.
Thanks in advanced.
Ayad Hindi
+Pie Number of slices to send: Send
It looks to me like there isn't a shortcut on this - you pretty much need to write a whole new jar file. The same problem seems to exist for zip files. Annoying but true.
One possibility is, if you simply want to add new files, not remove or modify old ones, you can use Runtime exec() to invoke the jar command with the -u option. E.g.
jar uf foo.jar foo.class
would add the file foo.class to the existing JAR file foo.jar. Of course by using exec() you'd be giving up portability. Might be worthwhile in some cases - but you're proably better off with your first strategy.
If anyone knows of an alternative, please speak up.
+Pie Number of slices to send: Send
Thanks for the reply.
So I guess I'll have to stick to the firdst approach. I can't use exe() since portability is essential.
Thanks
Ayad Hindi
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1109 times.
Similar Threads
Error in Struts2 application
Jar files & JarOutputStream
Compiler error
Instantiating classes in jar file used by Web project
Access denied exception in applet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 21:53:15.