一般maven 結構
mavenPro01
src
-main
-java
-package
-test
-java
-package
pom.xml
maven常用命令
mvn -v 查看maven的版本
compile 編譯
test 測試
package 打包
clean 刪除target
install 安裝jar到本地倉庫中
自動創建目錄骨架
創建目錄的兩種方式:
1.archetype:generate 按照提示進行創建
2.archetype:generate -DgroupId=組織名 ,公司網址的反寫+項目名
-DartifactId=項目名-模塊名
-Dpackage=代碼所在的包名
maven生命週期
clean 清理項目, default 構建項目, site 生成項目站點 , 三個都是獨立的生命週期。
clean 內的三個階段
pre-clean 執行清理前的工作
clean 清理上一次構建生成的所有文件
post-clean 執行清理後的文件
default 最核心
compile test package install
site 內的幾個階段
pre-site 在生成項目站點前要完成的工作
site 生成項目的站點文檔
post-site 在生成項目站點後需要完成的工作
site-deploy 發佈生成的站點到服務器上
maven插件等 - 可參考官方文檔
pom.xml中代碼片段, source插件,將源碼打入jar內。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
pom.xml 常用標籤
<!-- 指定當前pom版本 -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.xiong.InvPro</groupId>
<artifactId>InvPro</artifactId>
<!--
第一個0表示大版本號
第二個0表示分支版本號
第三個0表示小版本號
0.0.1
snapshot快照
alpha內部測試
beta公測
release穩定版本
GA正式發佈
-->
<version>1.0-SNAPSHOT</version>
<!--
默認是jar
war zip pom
-->
<packaging>war</packaging>
<name>InvPro Maven Webapp</name>
<url>http://maven.apache.org</url>
<description>項目描述</description>
<!-- 開放人員信息 -->
<developers></developers>
<!-- 依賴管理 -->
<dependencyManagement>
</dependencyManagement>
<dependencies>
<!-- junit4 test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- 依賴範圍 -->
<scope>test</scope>
<!-- 設置依賴是否可選,默認爲false -->
<optional></optional>
<!-- 排除依賴傳遞列表 -->
<exclusions>
<exclusion></exclusion>
</exclusions>
<version>${junit4.version}</version>
</dependency>
</dependencies>
http://www.iteye.com/topic/973166