• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properties file

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any specific switch to pass a Properties file from the command line?
 
Dirk Schreckmann
Sheriff
Posts: 7023
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nope. You need to parse the commandline yourself and determine which is the properties file.
Or more likely you will force a specific name and location on the file and read it from there.
Or have another properties file at a specific name and location and read the name and location of the properties file from there
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I was looking for something of the Properties class in conjunction with the -D switch... Rather then saying arg1=value1 arg2=value2 ... to pass a file.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you pass the pathname to the file into the main method, you can create from that String a FileInputStream which can then be loaded into a Properties object.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use the -D option in conjunction with some new system property - e.g.
java -Dleslies.properties.file=foo/bar/config.properties MyClass
Then use that system property to load the Properties:
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a KISS rule! Thanks JRY
I think the Properties file should not be part of cmd-line-args-validation and your solution is a compromise.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic