Apache Maven

Apache Maven 是什么

Manve 是软件项目管理和编译的工具, 基于POM(Project Object Model)使项目的构建(build),分发(distribute) 更容易. 一个POM是一个XML文档, 类似于Java中的Object, 所有POM也都是一个Super POM的子脚本

下载/安装 Maven

下载

https://maven.apache.org/download.cgi

  • 注意要求的Java 版本. 

安装

前置条件 - 配置了对应的Java版本(JAVA_HOME 和PATH)

安装步骤 - 

1. 下载后先解压到任意目录

unzip apache-maven-3.9.6-bin.zip

tar xzvf apache-maven-3.9.6-bin.tar.gz

2. 设置环境变量

添加apache-maven-x.x.x/bin目录到PATH 中. 如果不知道如何设置可以查询一下这里就不赘述了. 

3. 测试结果

mvn -v

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /opt/apache-maven-3.9.6
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"

运行

mvn [options] [<goal(s)>] [<phase(s)>]

The built-in lifecycles and their most used phases, in order, are:

  • clean - clean

  • default - validatecompiletestpackageverifyinstalldeploy

  • site - sitesite-deploy

常用的Options的作用, 每个Option都是一个Plugin:

Core Plugins描述
cleanClean up after the build.
compilerCompiles Java sources.
installInstall the built artifact into the local repository.

参考:  Maven – Available Plugins

  • Build plugins will be executed during the build and they should be configured in the <build/> element from the POM.
  • Reporting plugins will be executed during the site generation and they should be configured in the <reporting/> element from the POM.

配置

Maven – Configuring Apache Maven

  • 修改.m2的位置
  • 设置代理
  • JVM参数等

Project Object Manage(POM )

Maven – POM Reference

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <!-- The Basics -->
  <groupId>项目所属group id, 一般为公司域名倒写. 例如 org.apache.maven </groupId> 

  <artifactId>一个具体的项目</artifactId>

  <version>项目版本</version>

  <packaging>...</packaging>

  <dependencies>...</dependencies>

  <parent>父工程的 artifactId</parent>

  <dependencyManagement>...</dependencyManagement>

  <modules>...</modules>

  <properties>...</properties>
 
  <!-- Build Settings -->
  <build>...</build>

  <reporting>...</reporting>
 
  <!-- More Project Information -->
  <name>...</name>

  <description>...</description>

  <url>...</url>
  <inceptionYear>...</inceptionYear>

  <licenses>...</licenses>

  <organization>...</organization>

  <developers>...</developers>

  <contributors>...</contributors>
 
  <!-- Environment Settings -->
  <issueManagement>...</issueManagement>
  
  <ciManagement>...</ciManagement>
   
  <mailingLists>...</mailingLists>
  
<scm>...</scm>
  
<prerequisites>...</prerequisites>
  
<repositories>...</repositories>

  <pluginRepositories>...</pluginRepositories>
  
<distributionManagement>...</distributionManagement>

  <profiles>...</profiles>

</project>

参考文档

Maven – Welcome to Apache Maven

maven repository详解_java_脚本之家

https://mvnrepository.com/

未完待续....

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值