Meaningless Drivel is fun!
The moose likes Java in General and the fly likes extracting from a jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "extracting from a jar file" Watch "extracting from a jar file" New topic

extracting from a jar file

Dave Jones
Ranch Hand

Joined: Feb 20, 2005
Posts: 77
Hello all !!
I need to read some data from a file that is in a jar form.
until now, I used :

and it worked just fine, BUT , this works only if I am running it from the jar itself !, I now need to read from a different Jar !, can someone give me a hand here ? this is supposed to be simple, I don't really know why I got tangled up with this ....

Thanks in advance, Dave
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211


Check out java.util.jar
package. The classes JarFile, and JarEntry is what you need. You should be able to find a fair few examples too, if you google for it.



The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Pradeep Kadambar
Ranch Hand

Joined: Oct 18, 2004
Posts: 148
Probably using the ClassLoader to load the resource will solve the problem. It doesn't matter as long as the resource is in the classpath.

Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
If you just want to read property files or images, you might want to consider ResourceBundle or Property classes, which can read anything present in the classpath (even if from another JAR file).

Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
Dave Jones
Ranch Hand

Joined: Feb 20, 2005
Posts: 77
Thank you all !
And special thanks to Sonny Gill !
I used the JarFile and it worked like a charm !
I got it up and running in no time !
Thanks again
I agree. Here's the link:
subject: extracting from a jar file
It's not a secret anymore!