maven的基本使用

时间:2021-09-20
本文章向大家介绍maven的基本使用,主要包括maven的基本使用使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
  1. 去官网下载安装
  2. 配置环境变量

  3. 设置本地仓库存放的路径
  4. 设置阿里镜像源
  5. idea中maven的基本使用
    5.1
    5.2
    5.3
    5.4
    5.5
    5.6
    5.7 项目创建成功后,记得看一下设置中idea中maven的设置,因为有的项目idea会默认使用自带的maven

    5.8
    5.9 不使用maven的模板创建maven项目

    5.10

    5.11 在之前用模板创建的maven的javaweb项目中补全文件夹
  6. 配置tomcat
    6.1
    6.2
    6.3
    6.4 选择第一个即可
    6.5
    6.6
  7. idea中maven窗口
  8. pom核心文件
<?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>com.daweiguo</groupId>
  <artifactId>maven_use</artifactId>
  <version>1.0-SNAPSHOT</version>
<!--  打包方式-->
<!--  jar是java应用-->
<!--  war是javaweb应用-->
  <packaging>war</packaging>

  <name>maven_use Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>
<!--配置-->
  <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>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

<!--  项目构建用的东西-->
  <build>
<!--    在build中配置resources,来配置我们资源导出失败的问题-->
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <excludes>
          <exclude>**/*.properties</exclude>
          <exclude>**/*.xml</exclude>
        </excludes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>

    <finalName>maven_use</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>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

“热爱是所有的理由和答案”。

原文地址:https://www.cnblogs.com/daweiguo/p/15314134.html