我們通過查詢可以瞭解Maven的基本用法,包括如何編譯,打包,以及安裝,或者生成文檔等等,但是當一個團隊共同使用同一個Maven的profile文件時,由於每個人的電腦安裝軟件,保存資源的路徑不同,或者個人電腦與服務器環境不同,就會帶來一系列問題:
1 對項目進行打包部署時需要更改pom.xml,以便編譯器選擇服務器對應的resource文件。如果忘記更改,則造成打包錯誤。
2 因爲每個人的pom.xml不同,導致pom.xml文件無法正常提交,必須手工去掉個人信息。
3 使用eclipse時,可以在Maven設置默認profile, 由於更改pom.xml並不能自動更新默認的profile,造成不必要的麻煩。
下面簡要介紹如何通過正確配置profiles來避免以上的問題。
假設我有一個臺式機,profile設定爲desktop, 還有一個筆記本,profile設定爲laptop, 服務器的profile設定爲server.
臺式機需要採用的resource是application-desktop, 筆記本application-laptop, 服務器application-server
<profiles>
<profile>
<id>desktop</id>
<properties>
<env>desktop</env>
</properties>
</profile>
<profile>
<id>desktop-build</id>
<properties>
<env>server</env>
</properties>
</profile>
<profile>
<id>laptop</id>
<properties>
<env>laptop</env>
</properties>
</profile>
<profile>
<id>laptop-build</id>
<properties>
<env>server</env>
</properties>
</profile>
<profile>
<id>server</id>
<properties>
<env>server</env>
</properties>
</profile>
</profiles>
這樣在臺式機可以設置desktop爲Maven默認值,而desktop-build爲編譯時的默認值
同樣也可以把用戶名作爲profile的id進行設置,道理是一樣的。
Good Luck,
Cheers!