maven

Maven是什么

 是一种项目管理工具,提供了一个项目对象模型(POM文件)的概念来管理项目的构建,统一了开发规范,最强大的功能就是能够自动下载项目依赖库。

Maven安装

 1、下载Maven:http://maven.apache.org/download.cgi

 2、解压Maven,并添加到环境变量:

    

    path:

    

 3、校验maven :

    

 4、配置本地仓库(maven解压目录中setting.xml文件,目录可自定义):

     

Maven仓库类型

  

本地仓库


 本地仓库存在于本地的电脑上,也就是maven解压目录中setting.xml文件里localRepository配置的路径。

远程仓库


 远程仓库也就是私服,存在于局域网中,一般的公司都有自己的远程仓库,因为外站的中央仓库宽带很慢;

 远程仓库可以下载中央仓库的jar包,也可以定制私有的jar包。

中央仓库


 存在于互联网上,几乎包含了所有开源的jar包,由Apche团队维护。

Maven整合Eclipse

配置Maven


 1、查看elipse是否安装maven插件:

      help 》 About Eclipse 》 Installation Details 》 在搜索框输入maven, 已安装图示:

      

2、配置maven安装目录

  

3、配置settings文件:

  

4、设置是否下载源码以及doc文件:

  

5、构建maven索引

  

构建Maven项目


 1、新建maven项目:

  File 》 New 》 Project 》 选择Maven Project

  

2、勾选Create a simple project(skip archetype selection):

   这里是为了工程目录的完整性。

  

3、编辑项目信息

   

4、在项目的src/main/webapp目录下创建WEB-INF目录及web.xml文件:

      这是为了解决pom.xml文件报错问题。

  

5、配置pom.xml文件来设置项目中的jdk、tomcat、jar或者其他信息,并在设置完更新maven项目:

     ssm配置的pom文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.hxb</groupId>
  <artifactId>maven_web</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  
    <!-- 版本锁定 -->  
    <properties>  
        <spring.version>4.3.3.RELEASE</spring.version>  
    </properties>  
    
    
    
  <dependencies> 
        <!-- MySQL -->  
        <dependency>  
            <groupId>mysql</groupId>  
            <artifactId>mysql-connector-java</artifactId>  
            <version>5.1.38</version>  
        </dependency>  
        
        <dependency>  
          <groupId>junit</groupId>  
          <artifactId>junit</artifactId>  
          <version>4.9</version>  
          <scope>test</scope>  
        </dependency>  
      
        <!-- 加入Servlet -->  
        <dependency>  
            <groupId>javax.servlet</groupId>  
            <artifactId>servlet-api</artifactId>  
            <version>2.5</version>  
            <scope>provided</scope>  
        </dependency>  
          
          <!-- Log4j -->  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
            <version>1.2.17</version>  
        </dependency> 
        
         <!-- 引用c3p0 依赖 start-->  
        <dependency>  
            <groupId>com.mchange</groupId>  
            <artifactId>c3p0</artifactId>  
            <version>0.9.2.1</version>  
        </dependency> 
        
        <!-- JSTL -->  
        <dependency>  
            <groupId>jstl</groupId>  
            <artifactId>jstl</artifactId>  
            <version>1.2</version>  
        </dependency>  
  
  
  
        <!-- 引入Spring(包含SpringMVC) 依赖 start -->  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-core</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-web</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-oxm</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-tx</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-jdbc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-webmvc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-aop</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context-support</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-test</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  
  
  
  
          <!-- MyBatis -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis</artifactId>  
            <version>3.2.5</version>  
        </dependency>  
        
        <!-- MyBatis整合Spring -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis-spring</artifactId>  
            <version>1.3.0</version>  
        </dependency>  
      
  </dependencies>  
  
  
  
  <build>  
    <finalName>hxb-SSM</finalName>  
    <plugins>  
    
        <!-- 指定jdk --> 
        <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-compiler-plugin</artifactId> 
            <configuration> 
                <source>1.8</source> 
                <target>1.8</target> 
            </configuration> 
        </plugin> 
        
          <!-- 加入Tomcat插件 -->  
    </plugins>  
  </build>  
</project>
View Code

  alt + F5更新maven项目:

  

一级标题

一级标题

二级标题


二级标题


二级标题


三级标题:

三级标题:

三级标题:

三级标题:

一级标题

一级标题

二级标题


二级标题


二级标题


三级标题:

三级标题:

三级标题:

三级标题:

原文地址:https://www.cnblogs.com/dahuandan/p/7401046.html