Maven: 如何在properties檔案中獲取maven的 pom.xml 的鍵值
阿新 • • 發佈:2018-12-31
轉自:http://blog.csdn.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即可