• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions about properties files  RSS feed

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have two questions about properties files.
1. Is it possible to import a properties file from another properties file?
2. Is it possible to have variables in a properties file as described below in code snippet.
Thanks in advance,
Julien.

Code snippet:

var_one=foo
var_two=$var_one bar

The second line would then read "foo bar"
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to 1) No. You can load two files into two Properties objects, and merge them using the putAll method, though.

to 2) Not exactly like that. You can use "var_two={0} bar", and then {0} (and {1} etc.) is a variable that you can set programmatically later, but you can't directly reference other properties like in your example.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Acctually,

1) Yes, kind of. Suppose you have two properties files in the "resources" directory (which also is in the classpath). The names of the files could be:
  • propfile1.properties
  • propfile2.properties


  • The contents of the "propfile1.properties" file could include:



    Then it would be a matter of loading the first properties file, extracting the name of the second one, and then loading that one as well.




     
    Ranch Hand
    Posts: 1780
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Julien Martin:

    2. Is it possible to have variables in a properties file as described below in code snippet.

    var_one=foo
    var_two=$var_one bar

    The second line would then read "foo bar"


    Ant lets you write property files like that, in Ant syntax, of course:

    var_one=foo
    var_two=${var_one} bar

    I would suggest you check out Ant's API and see if you can reuse some of its functionality.
     
    You can't have everything. Where would you put it?
    Rocket Oven Kickstarter - from the trailboss
    https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!