How a JAR file can read an external properties file

后端 未结 7 1114
星月不相逢
星月不相逢 2020-12-24 10:01

We have a connection pooling component (JAR file) for one of our application. As of now the application connection details are bundled with-in the JAR file (in .proper

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 10:09

    Simplest way is below. It will load application.properties from cfg folder outside of the jar file.

    Directory Structure

      |-cfg-->application.properties
      |-somerunnable.jar
    

    Code:

        Properties mainProperties = new Properties();
        mainProperties.load(new FileInputStream("./cfg/application.properties"));
        System.out.println(mainProperties.getProperty("error.message"));
    

提交回复
热议问题