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

5
  • 4
    System.getProperty("config.dir") Commented Oct 26, 2018 at 15:31
  • @Glains in this case this will not work as value for config.dir property is not passed as a parameter to the main method Commented Oct 26, 2018 at 15:34
  • ty Ivan I will try that. Commented Oct 26, 2018 at 15:34
  • @Praveen do not use spaces in java command line -Dconfig.dir = ../../.. use it as -Dconfig.dir=../../.. and then use @Ivan comment BTW: @Glains you are not right. Commented Oct 26, 2018 at 15:36
  • See also stackoverflow.com/questions/5045608/… Commented Oct 26, 2018 at 16:08

2 Answers 2

0

Ivan gave the correct answer in a comment.

System.getProperty("config.dir")

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

yeah cant have properties file inside project.Will foolow Ivan's comment
@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
ooh I was not aware of that let me try that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.