Maven环境搭建(学习笔记记录)

Java环境,eclipse编译器等环境就绪(for Windows 10):
1、 maven:http://maven.apache.org/download.cgi
选择如图版本:
这里写图片描述

2、解压zip包到本地,配置环境变量
MAVEN_HOME:D:\Maven\apache-maven-3.5.4
Path:追加;%MAVEN_HOME%\bin到后面
3、验证maven环境
cmd命令行验证:mvn -v
出现如下界面,环境配置成功。
这里写图片描述

4、在eclipse中配置maven
1)打开eclipse》点击Window》点击Preferences
这里写图片描述
2)点击Maven》选择installations》从本地路径引入刚才解压的maven文件(图中已加入)
这里写图片描述

3)同时注意配置User Settings》选择本地目录D:\Maven\apache-maven-3.5.4\conf\settings.xml引入
这里写图片描述
4)修改settings.xml文件
54行添加:

  <localRepository>C:\maven\repository</localRepository>

161行添加:

<mirror>
     <id>aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>aliyun Maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>

5)在第3)步骤操作的界面点击update settings,配置完成。

5、创建maven项目
在eclipse中点击new》project》maven project
这里写图片描述
点击next》next》next
这里写图片描述
点击finish 创建完成。

6、pom.xml文件

<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:组织 id(类似包名), artifactId:project name , version:default development 
        version , packaging:default jar -->
    <groupId>com.test.practice</groupId>
    <artifactId>maventest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>maventest</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <xmlFileName>testng.xml</xmlFileName>
    </properties>

    <!-- 依赖的jar包可从百度搜索,例如:maven testng -->
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</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.14.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.uncommons/reportng 依赖ReportNg,关联TestNg -->
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- 依赖Guice -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>3.0</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi 依赖poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl 依赖jxl -->
        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6.12</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- 添加插件 关联testNg.xml -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <!-- <suiteXmlFile>res/${testng2.xml}</suiteXmlFile> -->
                        <suiteXmlFile>res/testng2.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <!-- 加入编码设置,否则生成的报告会中文乱码 -->
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>
            <!-- 添加插件,添加ReportNg的监听器,修改最后的TestNg的报告 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <properties>
                        <property>
                            <name>usedefaultlisteners</name>
                            <value>false</value>
                        </property>
                        <property>
                            <name>listener</name>
                            <value>org.uncommons.reportng.HTMLReporter</value>
                        </property>
                    </properties>
                    <workingDirectory>target/</workingDirectory>
                    <!-- <forkMode>always</forkMode> -->
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

猜你喜欢

转载自blog.csdn.net/claiwhz123/article/details/81631595