0

I have a java app that looks something like this

java -Dconfig.dir = ../../.. -jar blah..

how can I access this config.dir in java application at run time.I am trying to load a properties file that will be there at run time.So I want to load this in file stream

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
Praveen
  • 557
  • 1
  • 5
  • 20

2 Answers2

0

Ivan gave the correct answer in a comment.

System.getProperty("config.dir")

Steve11235
  • 2,849
  • 1
  • 17
  • 18
0

For your use case, you need to add the location of the properties file in the class path and then follow the steps given in this answer.

If you really want to read the -D parameter, refer to @Ivan comment

Saptarshi Basu
  • 8,640
  • 4
  • 39
  • 58
  • yeah cant have properties file inside project.Will foolow Ivan's comment – Praveen Oct 26 '18 at 15:50
  • @Praveen You don't need to have the properties file in project to be able to add the location in classpath. You can add any random director location to the classpath using the `-classpath` java command line switch – Saptarshi Basu Oct 26 '18 at 15:56
  • ooh I was not aware of that let me try that – Praveen Oct 26 '18 at 16:00