maven

maven主要功能:java

項目構建web

   實際開發寫完代碼後的 編譯,打包,部署等工做均可以使用maven來完成apache

依賴管理json

    對jar包的管理 開發者只需將想要的jar包 經過pom.xml配置文件配置一下,maven會自動下載相關包api

 

1.下載 官網:http://maven.apache.org/download/app

2.解壓後目錄webapp

  bin:maven的命令maven

  boot:一個類加載器 一般狀況下不使用ui

  conf:maven的配置文件阿里雲

  lib:maven運行時須要的jar包

3.配置Maven環境變量

  MAVEN_HOME

  PATH          %MAVEN_HOME%\bin

4.驗證是否配置成功

  cmd mvn -v

  存放jar包的本地倉庫路徑     在settings.xml 中的 localRepository中 配置 ${user.home} /.m2/repository

 

項目默認 jdk 1.5每次update project自動變成1.5     要將其修改成1.8

  修改方法 pom.xml 中project節點下添加

<build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.8</source>
                  <target>1.8</target>
                  <encoding>UTF-8</encoding>
              </configuration>
          </plugin>
      </plugins>
  </build>

  改完maven--update   報錯Connot change version of project facet Dynamisc Wen Module to 2.3

              首先查看Java Compiler 是1.8 而後修改Project Facet -->Dynamic Web Moduler-3.1

              而後打開web.xml 將dtd版本改到3.1方法以下:

                新建Dynamic Web Project  名稱隨便寫 Next-->Next 勾選Generate web.xml deployment descriptor-->finish

                將生成的web.xml替換原來maven中的便可  後 maven-->update project

兩種方式新建 maven project                      

 一 . (Use default Workspace location )

  ①報錯 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

  方法:在pom.xml中添加

  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
  </dependency>

  ②打開Java Resource目錄只看見src/main/resources

  方法:properties-> Ⅰ Java Compiler Ⅱ Java Build Path  ⅡⅠ Project Dacets JRE->1.8版本

  便可自動生成src/main/java   src/test/java            缺一個src/test/resources  手動建立source folder便可

    src/main/webapp  至關於 Dynamic Web Project的 WebContent目錄

    target/m2e-wtp存放編譯後的文件

  二. Create a simple project (skip archetype selection) √

  Packaging -- war   

  ①報錯 web.xml is missing and <failOnMissingWebXml> is set to true 

    方法:在src/main/webapp下面建立 WEB-INF文件夾 再建立web.xm文件便可

 

pom.xml中每個dependency以下 對應一個jar包 maven會自動下載(若是以前已存在則再也不下載)

<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>fastjson</artifactId>
  <version>1.2.44</version>
</dependency>

 若是不知道怎麼寫dependency能夠去第三方庫(jar包對應官網)查找  通常都提供

若是沒有的話 能夠去maven中央倉庫查找  http://mvnrepository.com

maven倉庫

  本地倉庫  對應用戶下的.m2/repository

  遠程倉庫

    ①中央倉庫(在國外)  http://repo1.maven.org/maven2

    ②私服

  若是從中央倉庫下載速度比較慢,且不肯搭建私服,可從國內第三方Maven鏡像下載 eg阿里雲提供的maven鏡像

打開maven地址中的settings.xml 在mirrors標籤下添加

<mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>               
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>

修改完成後在Eclipse中修改

window->preferences->maven->installations->Add->找到本地maven所在目錄 apply便可

相關文章
相關標籤/搜索