简体   繁体   中英

how to get parameter value from pom.xml via config.properties

I want to receive the link specified in a pom.xml through a config.properties

I have:

<properties>
         <site_url>https://biz-trunk.rts-tender.ru/</site_url>
</properties>

in pom.xml ,

site_url = ${site_url}

in config.properties ,

private Properties properties = new Properties();
public void loadConfig() {
    InputStream input = null;
    try {
        input = new FileInputStream(getPropertiesFileName());
        properties.load(input);
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

to download config and this

在此处输入图片说明

Why???

在此处输入图片说明

Why is it not working???

Maven has concept of resource filtering . During build Maven will replace all available placeholders which look like ${some_text} with corresponding properties' values from pom.xml. If no property found then value will not be replaced.

在入口处的loadConfig()中必须是路径config.properties ,该路径在组装后在target/创建。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM