How to read the key-value pair of the pom file in the properties file in the maven project

I checked this question before and knew the answer, but I encountered it again recently, and then I must have wasted time to check it again. Although the problem is not big, it must not work like this every time, and it will seriously affect the efficiency. (ps: In fact, this is often the case. Maybe my memory is not good, and my brain is not working well...)

 

 We all know that using properties can store project-related configurations together in the form of key-value, and can quickly locate and replace them when they need to be modified. For example, the configuration related to the database link in the project is even so (refer to Figure 1 and Figure 2)

Then the project is distributed, so it is very troublesome to configure a lot of properties in many distributed applications, and there are also many project environments, such as development dev, test test, production prov, etc., so we can also pass in properties The custom attribute value in the pom file is obtained in the form of ${} placeholder in the file, and so on, the attribute value setting can be placed in the root pom file of the project's parent (Figure 3), so that All attribute values ​​are placed together, which is more convenient

 

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
And don't forget to set the value of the filtering property to true, that's it (I didn't find this configuration in my company's project, but it should be in the form of a plug-in)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326396382&siteId=291194637