[maven] maven入門之倉庫
$mvn -v
Apache Maven 3.0.5 (Red Hat 3.0.5-16.1)
Maven home: /usr/share/maven
Java version: 1.7.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.3.1.x86_64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.x86_64", arch: "amd64", family: "unix"
* 中央倉庫:
安裝完maven之後,
解開/usr/share/maven/lib/maven-model-builder.jar
檢視org/apache/maven/model/pom-4.0.0.xml
<project>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
* 增加映象:"/etc/maven/settings.xml"
<mirror>
<id>[email protected]</id>
<mirrorOf>central</mirrorOf>
<name>http://mvnrepo.163.com/nexus/content/groups/public</name>
<url>http://mvnrepo.163.com/nexus/content/groups/public</url>
</mirror>
建立一個Maven專案
$mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd my-app
$mvn help:effective-pom
$mvn help:describe -Dplugin=archetype
$mvn archetype:help -Ddetail=true -Dgoal=generate
mvn compile
mvn test-compile
mvn test
mvn site
mvn package
mavn 常用命令
1. 建立Maven的普通java專案:
mvn archetype:create -DgroupId=packageName -DartifactId=projectName
2. 建立Maven的Web專案:
mvn archetype:create -DgroupId=packageName -DartifactId=webappName -DarchetypeArtifactId=maven-archetype-webapp
3. 編譯原始碼: mvn compile
4. 編譯測試程式碼:mvn test-compile
5. 執行測試:mvn test
6. 產生site:mvn site
7. 打包:mvn package
8. 在本地Repository中安裝jar:mvn install
(mvn install -D maven.test.skip=true 跳過TestCase檢驗,否則在install時會執行TestCase測試)
9. 清除產生的專案:mvn clean
10. 生成eclipse專案:mvn eclipse:eclipse
11. 生成idea專案:mvn idea:idea
12. 組合使用goal命令,如只打包不測試:mvn -Dtest package
13. 編譯測試的內容:mvn test-compile
14. 只打jar包: mvn jar:jar
15. 只測試而不編譯,也不測試編譯:mvn test -skipping compile -skipping test-compile
( -skipping 的靈活運用,當然也可以用於其他組合命令)
16. 清除eclipse的一些系統設定:mvn eclipse:clean
References:
http://www.cnblogs.com/luotaoyeah/p/3785044.html Maven入門指南④:倉庫
http://aijezdm915.iteye.com/blog/1335025
http://www.mamicode.com/info-detail-1016489.html
http://www.iteye.com/topic/1126678
http://stevenfeng.iteye.com/blog/987623 maven常用命令