Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
Pay attention! Tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic