Maven: 怎么在properties文件中获取maven的 pom.xml 的键值
Maven: 如何在properties文件中获取maven的 pom.xml 的键值
原文链接:http://blog.****.net/bigtree_3721/article/details/51898095
如何在properties文件中获取maven的 pom.xml 的键值?
答案就是:在资源文件(*.properties)中放置pom.xml预先设置的变量, 在执行mvn package时就会自动将变量替换为真实值 例如: 1. 我们在src\main\resources\application.properties放置如下内容 version=${project.version} 2. 配置pom.xml让Maven to copy that file into your output classes and translate the resource during that copy, interpreting the property <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build> 3. 执行mvn package 查看生成的jar文件中的application.properties, version值已经变成了pom.xml中的version 因此我们只需使用java读取application.properties即可