- 版本
- Maven 3.2 要求 JDK 1.6 或以上版本, 而 Maven 3.0/3.1 需要 JDK 1.5 或以上
- 環境變量
- JAVA_HOME、M2_HOME(MAVEN_HOME部分應用要求配置MAVEN_HOME同樣指向maven安裝路徑)、path(2個bin)
- 代理
- {M2_HOME}/conf/settings.xml配置proxy,不用重啓,命令啓動會重新加載吊起
- 本地資源庫
- {M2_HOME}/conf/settings.xml配置localRepository,默認{username}/.m2
- 中央資源庫
- http://search.maven.org/,Maven命令自動獲取庫文件http://repo1.maven.org/maven/
- 遠程資源庫文件
- pom.xml的repository標籤
-
<repositories> <repository> <id>java.net</id> <url>https://maven.java.net/content/repositories/public/</url> </repository> </repositories>
-
- 安裝到本地
-
mvn install:install-file -Dfile=帶路徑&版本.jar -DgroupId=groupId -DartifactId=artifactId -Dversion={version} -Dpackaging=jar
-
- pom.xml的repository標籤
-
pom.xml依賴jar
-
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>
-
-
從Maven模板創建項目
-
命令行到要創建項目的目錄:DarchetypeArtifactId指定模板名
-
mvn archetype:generate -DgroupId=包,例如com.stu -DartifactId={project-name}-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
-
-
模板
-
maven-archetype-quickstart 快速開始
-
maven-archetype-webapp Web項目
-
-
-
JDK版本指定
-
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build>
-
-
打包mvn package 運行:java -cp target/**.jar com.xxx.XXX(執行類)
-
mvn eclipse:eclipse -Dwtpversion=2.0 生成Eclipse需要的項目文件 -Dwtpversion=2.0添加了會生成web項目,否則Java項目。若想默認是web需要在對應的mvn項目的pom.xml中增加wtpversion
-
<plugins> <!-- Eclipse project --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <!-- Always download and attach dependencies source code --> <downloadSources>true</downloadSources> <downloadJavadocs>false</downloadJavadocs> <!-- Avoid type mvn eclipse:eclipse -Dwtpversion=2.0 --> <wtpversion>2.0</wtpversion> </configuration> </plugin> </plugins>
-
Maven常用知識點
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.