Maven简单入门

Maven简单入门

在这里插入图片描述

1. Maven官网C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20200805201010054.png

2. 解压后

在这里插入图片描述

3. 配置环境变量

  • 配置
    在这里插入图片描述

  • 检查版本
    - [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rOzOHCa3-1596639982901)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20200805204303183.png)]

4. 添加阿里云镜像

在这里插入图片描述
在这里插入图片描述

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

5. 建立本地仓库

  • 创建本地仓库文件夹
    在这里插入图片描述

  • 修改settings.xml
    在这里插入图片描述

6. Idea中创建Maven项目

6.1首次创建Maven项目

在这里插入图片描述

6.2仓库建立成功

在这里插入图片描述

6.3 Idea中Maven相关配置

在这里插入图片描述
在这里插入图片描述

6.4 原始干净的目录结构

在这里插入图片描述

6.5 标记文件加属性

在这里插入图片描述

6.6 Maven项目配置Tomcat

在这里插入图片描述

  • 虚拟路径映射:不配置的话默认为localhost:8080
    在这里插入图片描述

    6.7Maven导航栏

在这里插入图片描述

6.8Maven pom.xml核心配置文件(web模板)

<?xml version="1.0" encoding="UTF-8"?>
<!--Maven版本和头文件-->
<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>
<!--项目配置GAV-->
  <groupId>org.example</groupId>
  <artifactId>javaweb</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--项目打包方式-->
  <packaging>war</packaging>

  <properties><!--配置-->
    <!--项目默认构建编码-->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  <!--项目依赖-->
  <dependencies>
    <dependency><!--具体依赖jar包-->
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!--Maven可以自动导入jar包所依赖的其他jar包-->
     <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.2.1.RELEASE</version>
    </dependency>

  </dependencies>
  <!--项目构建时模板用的东西-->
  <build>
    <finalName>javaweb</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
       .........
      </plugins>
    </pluginManagement>
  </build>
</project>

在这里插入图片描述

6.9 配置文件无法导出或生效解决方案

由于Maven约定大于配置,导致我们写的配置文件无法导出或生效的问题

  • 解决方案:

[关于在maven项目中配置文件资源导出问题]https://www.cnblogs.com/yuqiliu/p/12059614.html

 <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

6.10目录树

Maven中jar包结构的目录树
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值