Maven庫:
http://repo2.maven.org/maven2/
Maven依賴查詢:
【Maven常用命令】
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 clean compile
4. 清理測試:mvn clean test
5. 清理打包:mvn clean package
6. 清理安裝:mvn clean install
7. 生成eclipse項目:mvn eclipse:eclipse
8. 生成idea項目:mvn idea:idea
9. 編譯測試的內容:mvn test-compile
10. 只打jar包: mvn jar:jar
11. 跳過測試: mvn install -Dmaven.test.skip=true
11. 指定端口: mvn -Dmaven.tomcat.port=9090
12. 只測試而不編譯,也不測試編譯:mvn test -skipping compile -skipping test-compile ( -skipping 的靈活運用,當然也可以用於其他組合命令)
13. 清除eclipse的一些系統設置: mvn eclipse:clean
通過cvs或svn下載代碼到本機,然后執行mvn eclipse:eclipse生成ecllipse項目文件,然后導入到eclipse就行了;修改代碼后執行mvn compile或mvn test檢驗,也可以下載eclipse的maven插件。
發布第三方Jar到本地庫中: mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar。
【添加 jar 包到本地倉庫】
mvn install:install-file
-DgroupId=xxx
-DartifactId=xxx
-Dversion=1.0 //版本號
-Dpackaging=jar //類型
-Dfile=d:\xxx-1.0.jar //jar實際路徑
添加打包插件:
<plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> <compilerArguments> <extdirs>src\main\webapp\WEB-INF\lib</extdirs> </compilerArguments> </configuration> </plugin>
【庫版本選擇】
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>[1.1,)</version>
</dependency>
表達式 含義
(,1.0] version<=1.0
[1.2,1.3] 1.2<=version<=1.3
[1.0,2.0) 1.0<=version<2.0
[1.5,) 1.5<=version
(,1.1),(1.1,) version!=1.1
【pom.xml 基本節點】
<project> 根節點
<modelversion> pom.xml 使用的對象模型版本
<groupId> 創建項目的組織或團體的唯一 Id
<artifactId> 項目唯一Id, 項目名
<packaging> 打包擴展名(JAR、WAR、EAR)
<version> 項目版本號
<name> 顯示名,用於生成文檔
<url> 組織站點,用於生成文檔
<description> 項目描述,用於生成文檔
<dependency>之<scope> 管理依賴部署
<scope> 可使用 5 個值:
compile 缺省值,用於所有階段,隨項目一起發布
provided 期望JDK、容器或使用者提供此依賴。如servlet.jar
runtime 只在運行時使用
test 只在測試時使用,不隨項目發布
system 需顯式提供本地jar,不在代碼倉庫中查找