Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extracting from a jar file

 
Dave Jones
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave,

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.

HTH.

Sonny
 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Dave Jones
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic