Maven安装以及常用命令

mvn安装

1.下载地址http://maven.apache.org/download.cgi 下载apache-maven-3.6.3-bin.zip

2.解压到D:\apache-maven-3.6.3

3.将bin目录D:\apache-maven-3.6.3\bin添加到环境变量path

4.测试是否安装成功

C:\Users\admin>mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: D:\apache-maven-3.6.3\bin\..
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: D:\Program Files\Java\jdk1.8.0_181\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

5.配置本地存放日志和镜像源D:\apache-maven-3.6.3\conf\settings.xml

  1. 默认地址${user.home}/.m2/repository,修改为<localRepository>E:/repo</localRepository>

  2.修改国内镜像地址,红色部分为阿里云镜像(将默认国外镜像地址注释)

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <id>aliyunmaven</id>
      <name>aliyunmaven</name>
      <url>https://maven.aliyun.com/repository/public</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

mvn常用命令

mvn package 打包

mvn clean package 清理并打包

mvn package -DskipTests 打包跳过测试

mvn install 安装到本地

mvn compile 编译 可使用mvn clean compile

mvn clean 清理 清理路径

mvn --version 显示mvn版本

更多参考https://www.cnblogs.com/diandianquanquan/p/11966543.html

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>com.zsk</groupId>
    <artifactId>simple-okhttp</artifactId>
    <version>1.0.0</version>

    <properties>
        <!--设置源文件编码格式utf-8-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--设置输出编码格式utf-8-->
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <!--指定JDK1.8编译-->
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!--设置JDK1.8版本-->
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.58</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <descriptorRefs>
                        <!--将所有依赖都解压打包到生成物中-->
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <!-- 以下是将项目依赖打到一个包里-->
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- 绑定到package生命周期阶段上 -->
                        <phase>package</phase>
                        <goals>
                            <!-- 只运行一次 -->   
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

 

 

 

posted @ 2020-10-25 13:17  zincredible  阅读(945)  评论(0编辑  收藏  举报