Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jar files. Urgent Please Reply  RSS feed

 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!