Maven filter attribute file, replace the property value


pom.xml

    
1, Resources: 
Resources are defined under the file directory which will be replaced with a variable defined in the configuration file, we will project the general configuration file in the src / main / resources, like db, bean and so on, which used the the filter variable will be arranged in variable during packaging alternative to a fixed value 

Picture 1

filtering = true indicates that all properties file src / main / resources below placeholder will be replaced with the corresponding attribute value profile

Picture 2

filtering = false indicates src / main / resources all the following xml file placeholder will not be replaced with the corresponding attribute value profile

Picture 3

filtering = true indicates src / main / resources / META-INF / spring below the spring-comm-conf.xml file placeholder will be replaced with the attribute value defined in the profile, and the configuration of the file to targetPath under path

2、profiles:

id node only, when the project package, you need to specify

<activation>

    <activeByDefault>true</activeByDefault>

</activation>

Change a node is set as the default profile selected

Use the command maven package

mvn  clean -Dmaven.test.skip=true package -P dev

Wherein -P dev, dev profile is specified id, maven profile information may be used operating system, JDK information file exists, attribute values, etc. as a basis, to activate the corresponding profile, but also in the compilation phase, by adding the command mvn -PprofileId parameters to manually activate the corresponding profile using the 
binding profile and filter, we can easily use different formulations under different conditions 

3, packing

在执行打包命令时,maven会到src/main/resources下寻找*.properties类型的文件,将pom定义的key替换到properties文件对应的${value}。



想要提升自己,工作中遇到的问题,更多JAVA技术相关文章,微信扫一扫关注作者公众号

Guess you like

Origin www.cnblogs.com/onlys/p/11753684.html