How a JAR file can read an external properties file

后端 未结 7 1093
星月不相逢
星月不相逢 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:17

    public static String getPropertiesValue(String propValue) {
            Properties props = new Properties();
            fileType = PCLLoaderLQIOrder.class.getClassLoader().getResourceAsStream(propFileName);
            if (fileType != null) {
                try {
                    props.load(fileType);
                } catch (IOException e) {
                    logger.error(e);
                }
            } else {
                try {
                    throw new FileNotFoundException("Property file" + propFileName + " not found in the class path");
                } catch (FileNotFoundException e) {
                    logger.error(e);
                }
            }
            String propertiesValue = props.getProperty(propValue);
            return propertiesValue;
        }
    

    above methods works for me, just store your property file into directory from where to run your jar and provide that name in place of propFileName, when you want any value from property just call getPropertyValue("name").

提交回复
热议问题