Load Properties File Classpath Java

Load Properties File Classpath Java

If you want to read Properties file values using classpath then its mandatory to put property file in classpath otherwise you will get exception. If you keep your property file inside src folder then it will be available to the classpath. If your existing project structure have property file outside src folder then you will have to set path of the file in classpath. 

  • Sample Java project structure from where we will read JavaHonk.properties file and print all its key values.

Load Properties File Classpath Java

  • LoadPropertyFileJava.java

  • Output:

Load Properties File Classpath Java

If your properties file is in maven project structure below:

2016-09-06 23_12_16-Java EE - PureJavaTibcoPublisherConsumer_src_main_java_com_javahonk_messaging_Lo

  • Tibco.properties

  • Then you could read as below by¬†LoadPropertiesAndReadValue.java:

  • For details please read oracle documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *