• 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 from two property files using a relative path

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have two property files having key value pairs. While the names of the keys are the same, the values of these keys are different in these files. viz.

file1.properties
------------------
xsl_file_path=file:///C:/Documents and Settings/Desktop/My_workspace/MyAppWeb/webApplication/xsl/modify.xsl

file2.properties
------------------
xsl_file_path=file:///apps/softcopies/WebSphere/AppServer/installedApps/SomeNetwork/MyApp.ear/MyAppWeb.war/xsl/modify.xsl

I want to have a single properties file and i want to access the key and value pair using relative paths. Please tell me how i can achieve such a thing. If you can suggest me some tutorials or examples, i would really appreciate it.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want to merge these two properties files into one? If you wound up with the same key twice, what would be the "relative path"?

On my first Java job, I made a properties reader that loaded a map of maps. Given filename and key it returned a value:

Is that close to what you need?
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No i do not want to merger these two files. I want to have a single properties file with the below key and value:

file_all.properties
------------------
xsl_file_path=WEB-INF/xsl/modify.xsl

Now i would like to access this file viz modify.xsl which is placed in the WEB-INF/xsl folder/directory of mmy web project. Would it be possible to access this file irrespective of whether it is a jar/war/simple file?

From above post, you can see that i have two property files with different paths for the values. I would like to have a single property file which would work under any scenario.
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can:
1. pack all different values for the same name as one array value. You will need to use some wrapper for extract them, like

2. You can use postfix to name, like:

Method getEnvSuffx() can return something like "_win", "_unx", "_jar"
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I think I finally see what you're after. Sorry to be so dense. Look into getResource and getResourceAsStream on Class and ClassLoader. I have to say I never made them work, but this is the kind of thing they're for.
 
reply
    Bookmark Topic Watch Topic
  • New Topic