• maven常用命令


    转:https://www.cnblogs.com/frankyou/p/6062179.html   和   https://www.cnblogs.com/hiver/p/7850954.html

    1、mvn clean package(打包)

      先把命令行切换到Maven项目的根目录,比如:/d/xxxwork/java/maven-test,然后执行命令:

     mvn clean package

      执行结果如下:

    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building rtp-front 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ rtp-front ---
    [INFO] Deleting D:\xxxwork\Java\maven-test\target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ rtp-front ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 0 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ rtp-front ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
    [INFO] Compiling 13 source files to D:\CtripWork\Java\maven-test\target\classes
    [WARNING] /D:/xxxwork/Java/maven-test/src/main/java/ReadOnly.java: 某些输入文件使用了未经检查或不安全的操作。
    [WARNING] /D:/xxxwork/Java/maven-test/src/main/java/ReadOnly.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ rtp-front ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory D:\xxxwork\Java\maven-test\src\test\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ rtp-front ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ rtp-front ---
    [INFO] No tests to run.
    [INFO]
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ rtp-front ---
    [INFO] Building jar: D:\xxxwork\Java\maven-test\target\rtp-front-1.0-SNAPSHOT.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 2.284 s
    [INFO] Finished at: 2016-11-14T15:36:55+08:00
    [INFO] Final Memory: 15M/77M
    [INFO] ------------------------------------------------------------------------

     执行顺序:

    1、使用清理插件:maven-clean-plugin:2.5执行清理删除已有target目录(版本2.5);

    2、使用资源插件:maven-resources-plugin:2.6执行资源文件的处理(版本2.6);

    3、使用编译插件:maven-compiler-plugin:3.1编译所有源文件生成class文件至target\classes目录下(版本3.1);

    4、使用资源插件:maven-resources-plugin:2.6执行测试资源文件的处理(版本2.6);

    5、使用编译插件:maven-compiler-plugin:3.1编译测试目录下的所有源代码(版本3.1);

    6、使用插件:maven-surefire-plugin:2.12运行测试用例(版本2.12);

    7、使用插件:maven-jar-plugin:2.4对编译后生成的文件进行打包,包名称默认为:artifactId-version,比如本例生成的jar文件:rtp-front-1.0-SNAPSHOT,包文件保存在target目录下。

    备注:

    不管是compile、package还是install等前三个步骤都是必不可少的。

    2、maven 常见命令 -pl -am -amd

    假设现有项目结构如下

    dailylog-parent
    |-dailylog-common
    |-dailylog-web

    • 三个文件夹处在同级目录中
    • dailylog-web依赖dailylog-common
    • dailylog-parent管理dailylog-common和dailylog-web。

    根据资料已知:

    参数 全称 释义 说明
    -pl --projects Build specified reactor projects instead of all projects

    选项后可跟随{groupId}:{artifactId}或者所选模块的相对路径(多个模块以逗号分隔)

    -am --also-make If project list is specified, also build projects required by the list

    表示同时处理选定模块所依赖的模块

    -amd --also-make-dependents If project list is specified, also build projects that depend on projects on the list

    表示同时处理依赖选定模块的模块

    -N --Non-recursive Build projects without recursive

    表示不递归子模块

    -rf --resume-from Resume reactor from specified project

    表示从指定模块开始继续处理

    以下是在maven-3.3.9中的试验

    1. 在dailylog-parent目录运行`mvn clean install -pl org.lxp:dailylog-web -am`,结果

    • dailylog-common成功安装到本地库
    • dailylog-parent成功安装到本地库
    • dailylog-web成功安装到本地库

    该命令等价于`mvn clean install -pl ../dailylog-web -am`

    2. 在dailylog-parent目录运行`mvn clean install -pl ../dailylog-common -am`,结果

    • dailylog-common成功安装到本地库
    • dailylog-parent成功安装到本地库

    3. 在dailylog-parent目录运行`mvn clean install -pl ../dailylog-common -amd`,结果

    • dailylog-common成功安装到本地库
    • dailylog-web成功安装到本地库

    由于dailylog-parent并不依赖dailylog-common模块,故没有被安装

    4. 在dailylog-parent目录运行`mvn clean install -pl ../dailylog-common,../dailylog-parent -amd`,结果

    • dailylog-common成功安装到本地库
    • dailylog-parent成功安装到本地库
    • dailylog-web成功安装到本地库

    5. 在dailylog-parent目录运行`mvn clean install -N`,结果

    • dailylog-parent成功安装到本地库

    -N表示不递归,那么dailylog-parent管理的子模块不会被同时安装

    6. 在dailylog-parent目录运行`mvn clean install -pl ../dailylog-parent -N`,结果

    • dailylog-parent成功安装到本地库

    7. 在dailylog-parent目录运行`mvn clean install -rf ../dailylog-common`,结果

      • dailylog-common成功安装到本地库
      • dailylog-web成功安装到本地库
  • 相关阅读:
    遗传算法python实现
    lambda的一些用法
    Python遗传和进化算法框架(一)Geatpy快速入门
    电脑连接小爱同学音箱无法调节音量
    Shell脚本批量修改文件编码为UTF-8
    java实现 批量转换文件编码格式为UTF8
    POM添加规范
    SOFA框架跨包调用报错NoClassDefFoundError
    logger打印日志时加if (logger.isInfoEnabled())/if (logger.isDebugEnabled())
    对象,JSON,字符串,map之间的互转
  • 原文地址:https://www.cnblogs.com/wangle1001986/p/16115344.html
Copyright © 2020-2023  润新知