Maven基本操作

Maven环境变量配置

  • 创建文件

    1
    2
    3
    cd ~
    touch .bash_profile
    open -e .bash_profile
  • 写入bash_profile

    1
    2
    3
    4
    5
    M2_HOME=/Users/work/apache-maven-3.5.0/
    PATH=$M2_HOME/bin:$PATH

    export M2_HOME
    export PATH
  • 执行

    1
    source .bash_profile
  • 测试

    1
    mvn -v

安装jar和源码至本地仓库

  • jar
    mvn install:install-file -Dfile=/Users/xx-1.0.1.jar -DgroupId=xx -DartifactId=xx -Dversion=1.0.1 -Dpackaging=jar

  • source
    mvn install:install-file -Dfile=/Users/xx-1.0.1-sources.jar -DgroupId=xx -DartifactId=xx -Dversion=1.0.1 -Dpackaging=jar -Dclassifier=sources

scope

1
2
3
4
5
<dependency> 
<groupId>xx.xx.xx</groupId>
<artifactId>xx-xx</artifactId>
<scope>provided</scope>
</dependency>
说明
provided 打包时不包含,认为容器会提供
compile 默认,在编译、测试和打包阶段均有效
runtime 跳过编译,直接参与运行和测试
test 依赖性参与测试工作,包括测试代码的编译和运行,例如junit
system 包来自本地系统文件

打包命令

说明
package 测试、打包
install 测试、打包并安装至本地仓库
deploy 测试、打包并安装至本地仓库,且上传至Maven中央服务器

打包指定项目

-N,–Non-recursive,表示不递归子模块
-pl Module,–projects,选项后可跟随{groupId}:{artifactId}或者所选模块的相对路径(多个模块以逗号分隔)
-am,–also-make,表示同时处理选定模块所依赖的模块

------ 本文结束------

本文标题:Maven基本操作

文章作者:Perkins

发布时间:2019年06月24日

原始链接:https://perkins4j2.github.io/posts/725/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。