Maven常用知識點

  1. 版本
    1. Maven 3.2 要求 JDK 1.6 或以上版本, 而 Maven 3.0/3.1 需要 JDK 1.5 或以上
  2. 環境變量
    1. JAVA_HOME、M2_HOME(MAVEN_HOME部分應用要求配置MAVEN_HOME同樣指向maven安裝路徑)、path(2個bin)
  3. 代理
    1. {M2_HOME}/conf/settings.xml配置proxy,不用重啓,命令啓動會重新加載吊起
  4. 本地資源庫
    1. {M2_HOME}/conf/settings.xml配置localRepository,默認{username}/.m2
  5. 中央資源庫
    1. http://search.maven.org/,Maven命令自動獲取庫文件http://repo1.maven.org/maven/
  6. 遠程資源庫文件
    1. pom.xml的repository標籤
      1. <repositories>
        	<repository>
        	    <id>java.net</id>
        	    <url>https://maven.java.net/content/repositories/public/</url>
            </repository>
        </repositories>
    2. 安裝到本地
      1. mvn install:install-file -Dfile=帶路徑&版本.jar -DgroupId=groupId -DartifactId=artifactId -Dversion={version} -Dpackaging=jar
        
        

         

  7. pom.xml依賴jar

    1. <dependencies>
      	<dependency>
      		<groupId>junit</groupId>
      		<artifactId>junit</artifactId>
      		<version>4.11</version>
      		<scope>test</scope>
      	</dependency>
      </dependencies>

       

  8. 從Maven模板創建項目

    1. 命令行到要創建項目的目錄:DarchetypeArtifactId指定模板名

      1. mvn archetype:generate -DgroupId=包,例如com.stu -DartifactId={project-name}-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

         

    2. 模板

      1. maven-archetype-quickstart  快速開始

      2. maven-archetype-webapp  Web項目

  9. JDK版本指定

    1. <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>

       

  10. 打包mvn package 運行:java -cp target/**.jar com.xxx.XXX(執行類)

  11. mvn eclipse:eclipse -Dwtpversion=2.0 生成Eclipse需要的項目文件  -Dwtpversion=2.0添加了會生成web項目,否則Java項目。若想默認是web需要在對應的mvn項目的pom.xml中增加wtpversion

    1. <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>

       

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章