其实maven已经给出了方案, 就是在资源文件(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
3. 执行mvn package
查看生成的jar文件中的application.properties, version值已经变成了pom.xml中的version
因此我们只需使用java读取application.properties即可
转载仅供参考,版权属于原作者。祝你愉快,满意请采纳哦