• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Properties File by One Jar from Another

 
Dennis Putnam
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • 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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can access A jar content with ZipInputStream as:
 
Dennis Putnam
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect. I will give it a try. Thanks.
 
Dennis Putnam
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • 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
Java Python Ruby
  • Mark post as helpful
  • send pies
  • 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: 333
  • Mark post as helpful
  • send pies
  • 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
Java Python Ruby
  • Mark post as helpful
  • send pies
  • 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: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sheesh, that was too easy. No wonder I couldn't find it. Thanks.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic