Maven的个性化定制
用Maven的小伙伴都知道,Maven的宗旨是約定優于配置(Convention Over Configuration)。
在宗旨的前提下Maven也提供了個性化定制的Profile,讓我們看看使用方法哈!
首先讓我們一起看看Maven中的屬性,這個用的挺多的:
注:下面屬性請在pom文件里使用。項目中使用默認是不支持的須要自己配置。
? ? ? ? 內置屬性: ${basedir}項目根文件夾
? ? ? ? ? ? ? ? ? ? ? ? ? ${version} 項目版本
? ? ? ? Pom屬性: ${project.artifactId}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.build.sourceDirectory}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.build.testSourceDirectory}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.build.directory}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.outputDirectory}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.testOutputDirectory}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.groupId}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.version}
? ? ? ? ? ? ? ? ? ? ? ? ? ?${project.build.finalName}
? ? ? ? 自己定義屬性:Settings: ${settings.localRepository} 。引用settings.xml文件里的XML元素的值
? ? ? ? Java系統屬性: ${user.home}
? ? ? ??環境變量屬性: ${env.JAVA_HOME}
如今我們開始認識Profile。下面是一個簡單的Profile結構體:
<profiles><profile><id>dev</id><properties><db.driver>com.mysql.jdbc.Driver</db.dirver></properties></profile></profiles>定義一個id為dev、屬性db.driver為com.mysql.jdbc.Driver的Profile。
只定義即可了嗎?答案是否定的。我們須要激活Profile才干生效,我們能夠通過mvn clean install -P?dev激活。
(注:dev為激活ID,假設你想激活多個能夠mvn clean install -P?dev1,dev2使用,假設不想激活某一個用-P!dev1)
以上是一種激活方式,以下我們繼續介紹其它激活方式
activeByDefault默認激活:
<settings> ... <activeProfiles> <activeProfile>dev1</activeProfile> </activeProfiles> ... </settings> 系統屬性激活:
<profiles><profile><id>dev</id><properties><db.driver>com.mysql.jdbc.Driver</db.dirver></properties><activation> <property> <name>test</name> <value>driver</value></property></activation> </profile></profiles>注:上面表示test=driver時才激活, mvn clean install -Dtest=driver
系統環境激活:
<profiles><profile><id>dev</id><properties><db.driver>com.mysql.jdbc.Driver</db.dirver></properties><activation> <jdk>[1.5,1.8)</jdk><file> <missing>oracle.properties</missing> <exists>jdbc.properties</exists> </file></activation></profile></profiles>注:上面表示jdk為1.5、1.6和1.7的時候激活? ? ? ? ?存在jdbc.properties文件情況,不存在oracle.properties文件情況激活
Profile種類等就不介紹了,用處不大。文章夠長了,自己都看不下去了。
總結
以上是生活随笔為你收集整理的Maven的个性化定制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 播放RTMP协议的流媒体的几种选择
- 下一篇: oracle用户创建和授权(一)