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>