Maven的基础

一、Maven的概念

Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具和构建工具。基于java,使用必须有jdk

二、maven的作用

作用:项目的打包,部署,管理项目的jar包

三、maven的使用

1.下载maven

2.配置maven的环境变量

 3.查看maven是否配置好

win+r --cmd--mvn -version 查看是否配置好

四、修改maven的中央仓库的存储位置

 1.中央仓库(从这里可以下载jar包)

中央仓库 https://mvnrepository.com/

2.修改存储在本机的本地仓库的位置

在setting.xml 中修改

<localRepository>D:/.m2/repository</localRepository>

3. 可以下载中央仓库的位置  用阿里云的中央仓库,下载的jar包的速度更快

 <mirror>

<id>alimaven</id>

<name>aliyun maven</name>

<url>http://maven.aliyun.com/nexus/content/groups/public/</url>

<mirrorOf>central</mirrorOf>

</mirror>

4.maven默认使用编译器 maven3使用jdk1.5修改为jdk1.8版本的

<profile>
    <id>jdk-1.8</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.8</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

五.创建 maven 工程

 1.创建maven框架

 

 

2.在pom.xml中导入各个框架所依赖的jar包

<properties>
    <mysql-version>5.1.47</mysql-version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql-version}</version>
    </dependency>

 3.tomcat的插件 写在pom.xml 中

<build>
    <plugins>
          <plugin>
             <groupId>org.apache.tomcat.maven</groupId>
             <artifactId>tomcat7-maven-plugin</artifactId>
             <version>2.2</version>
            <!--控制tomcat端口号 -->
             <configuration>
                <port>8080</port>
            <!-- 发布到tomcat后的名称 -->
            <!--/ 相当于把项目发布成ROOT -->
                <path>/</path>
                <uriEncoding>UTF-8</uriEncoding>
            </configuration>
          </plugin>
      </plugins>
 </build>

运行使用对pom.xml 右键 run as maven build ---》输入命令 tomcat7:run

六、maven的生命周期

mvn clean 清除项目目录中的生成结果 清理周期

默认生命周期

mvn compile 编译源代码

mvn test-compile 编译测试源代码

mvn test 运行应用程序中的单元测试

mvn package 根据项目生成的jar,war

mvn install 在本地Repository中安装jar

 七、maven的继承和聚合

1.继承

子工程继承父工程,会把父工程所有依赖继承下来

<parent>
    <groupId>org.lanqiao</groupId>
    <artifactId>maven-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

2.聚合

聚合:父工程聚合所有的子工程

<modules>
  	<module>maven-service</module>
  	<module>maven-common</module>
    <module>maven-controller</module>
  </modules>

当对父工程进行编译、测试、打包、安装、部署的时会同时对所有的子工程进行相应的操作

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值