maven快速上手

Maven使用思路:

(1)项目根目录创建pom.xml 文件

(2)添加项目依赖,刷新使得maven下载依赖

(3)项目编译、测试、打包、安装

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <!--com.公司或组织名.项目名-->
    <groupId>com.autotest</groupId>
    <!--子项目名-->
    <artifactId>selenuimUITest01_2.9</artifactId>
    <!--项目版本-->
    <version>1.0-SNAPSHOT</version>
  
    <!--maven的一些重要属性--> <properties> <!--编译的jdk--> <maven.compiler.source>16</maven.compiler.source> <maven.compiler.target>16</maven.compiler.target> <!--解决test输出警告--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!--需要引入的依赖--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.1</version>
        <!--依赖作用范围-->
<scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.13.0</version> </dependency> </dependencies> </project>

一、创建maven项目

(1)(ide)创建项目时,直接新建maven项目 

  • 创建src/main/java目录,该目录编写项目主代码;
  • 创建src/test/java目录,该目录编写项目测试代码;

(2)为旧项目添加pom文件,变为maven项目

二、添加maven依赖

在 https://mvnrepository.com/,搜索需要的依赖,把对应的dependency复制过来

三、项目编译、测试、打包、安装--层次递进的关系

编译:mvn clean compile

编译+测试:mvn clean test

编译+测试+打包:mvn clean package

编译+测试+打包+安装(到本地仓库):mvn clean install

posted @ 2022-02-09 18:01  低手寂寞  阅读(37)  评论(0)    收藏  举报