• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading Properties File by One Jar from Another

 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 jar files (A and B) where A is an obsolete version and B is the new version of my app. To do the "update" all I need is to obtain the properties from A. How can I programatically read A's properties from B? When I search for examples of this I can only find JarInJar situations rather than external jars. TIA.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can access A jar content with ZipInputStream as:
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect. I will give it a try. Thanks.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not doing what I expected in that it is not traversing directories. I have exactly 2 directories at the top level of the jar: KCBSEvents and META-INF. However, the only one it finds is META-INF. The main directory is not showing up. Here is my class:

How do I drill down to the file I need. It is in 'KCBSEvents/resources'? I don't think the way I am setting up BufferedReader is right either but I haven't gotten that far yet. TIA.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That else block (33 - 35) shouldn't be there. What you did actually is this: get the first entry from the jar, and if it's not what I'm looking for, exit application.

Edit: I hope you don't plan to handle your exceptions by exiting application. Suppose this is just a testing version.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DOH! How dumb is that? Yes this is a work in progress. I'll clean up all the exception handling when I have it working.

Can you also tell me how to set up the BufferedReader for my file? I can't seem to get anything that results in an inputStreamReader.

Thanks.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once you are in that while loop and you find the file you want to read:

Don't forget to close those input streams you are using (I think you omitted inputStream.close() after while loop). Or use try-with-resources instead.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sheesh, that was too easy. No wonder I couldn't find it. Thanks.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic