maven常用命令说明

在项目开发中,如果项目是用maven来构建的话,了解常用的命令是有必要的,虽然IDE已经自带了很多maven命令,但是有个前提就是你必须知道这些命令的意思 以下均是在window系统运行。
执行maven命令,一般设置好环境变量,方便想在任何目录下执行
MAVEN_HOME,表示maven的安装目录
Path,添加%MAVEN_HOME%\bin

下面贴出我在开发中常用的命令
  • 当前maven的版本信息,mvn -v
  • 输出如下
    Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:4
    7+08:00)
    Maven home: D:\maven3\bin\..
    Java version: 1.7.0_55, vendor: Oracle Corporation
    Java home: C:\Java64\jdk1.7.0_55\jre
    Default locale: zh_CN, platform encoding: GBK
    OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
  • mvn package   打包
  • mvn install   安装至本地仓库
  • mvn deploy    发布至远程仓库
  • mvn clean     清理生成的文件,如target
  • mvn compile   编译
  • mvn test-compile   测试代码编译
  • -Dmaven.test.skip=true    跳过测试
  • mvn test      测试
  • mvn jar:jar   打jar包
  • mvn jetty:run 启动jetty容器
  • mvn archetype:generate 构建项目
  • maven命令的使用帮助,mvn -h
  • mvn eclipse:clean    清除eclipse的一些系统设置              
  • mvn eclipse:eclipse  生成 Eclipse 项目文件
  • mvn archetype:generate -DarchetypeCatalog=internal -DarchetypeArtifactId=maven-archetype-quickstart 生成java项目
  • mvn archetype:generate -DarchetypeCatalog=internal -DarchetypeArtifactId=maven-archetype-webapp 生成web项目
  • mvn dependency:tree   查看依赖树
  • mvn compile war:war   打war包
  • usage: mvn [options] [<goal(s)>] [<phase(s)>]
    Options:
    -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)
    -B,--batch-mode 以没有交互模式执行(Run in non-interactive (batch)  mode)
    -b,--builder <arg> 构建策略使用的ID(The id of the build strategy to use.)
    -C,--strict-checksums 如果检查不通过,则构建失败(Fail the build if checksums don't match)
    -c,--lax-checksums 如果检查不通过,则警告(Warn if checksums don't match)
    -cpu,--check-plugin-updates 无效,仅保持向后兼容(Ineffective, only kept for backward compatibility)
    -D,--define <arg> 定义一个系统属性(Define a system property)
    -e,--errors 产生执行的错误消息(Produce execution error messages)
    -emp,--encrypt-master-password <arg> 用来加密的主安全密码(Encrypt master security password)
    -ep,--encrypt-password <arg> 用来加密的服务密码(Encrypt server password)
    -f,--file <arg> 强制使用的POM文件(或者pom.xml所在目录)( Force the use of an alternate POM file (or directory with pom.xml).)
    -fae,--fail-at-end 仅在构建最后提示失败;允许所有无影响的构建( Only fail the build afterwards; allow all non-impacted builds to continue)
    -ff,--fail-fast 在构建中,遇到失败就停止构建(Stop at first failure in reactorized builds)
    -fn,--fail-never 不管结果如何,构建永不失败(NEVER fail the build, regardless of project result)
    -gs,--global-settings <arg> 替换全局设置文件的路径(Alternate path for the global settings file)
    -gt,--global-toolchains <arg> 替换全局工具链文件(Alternate path for the global toolchains file)
    -h,--help 显示帮助信息(Display help information)
    -l,--log-file <arg> 构建输出的日志文件路径(Log file where all build output will go.)
    -llr,--legacy-local-repository 使用Maven 2传统的本地库的表现方式,即不使用_remote.repositories。也能通过使用 -Dmaven.legacyLocalRepo=true来激活(Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also be activated by using -Dmaven.legacyLocalRepo=true
    -N,--non-recursive 不要递归子工程(Do not recurse into sub-projects)
    -npr,--no-plugin-registry 无效,仅保持向后兼容(Ineffective, only kept for backward compatibility)
    -npu,--no-plugin-updates 无效,仅保持向后兼容(Ineffective, only kept for backward compatibility)
    -nsu,--no-snapshot-updates 禁止快照版更新(Suppress SNAPSHOT updates)
    -o,--offline 离线模式(Work offline)
    -P,--activate-profiles <arg> 激活以逗号隔开的profiles(Comma-delimited list of profiles to activate)
    -pl,--projects <arg> 以逗号隔开指定构建工程代替所有构建工程。一个工程可以通过[groupId]:artifactIdh或者相对路径来指定。( Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path.)
    -q,--quiet 安静的输出,仅显示错误( Quiet output - only show errors)
    -rf,--resume-from <arg> 从指定的工程恢复反应(Resume reactor from specified project)
    -s,--settings <arg>    替换用户设置文件的路径(Alternate path for the user settings file)
    -T,--threads <arg> 线程个数(Thread count, for instance 2.0C where C is core multiplied)
    -t,--toolchains <arg> 替换用户的工具链文件路径(Alternate path for the user toolchains file)
    -U,--update-snapshots 强制检查丢失的正式版和更新快照版(Forces a check for missing releases and updated snapshots on remote repositories)
    -up,--update-plugins 无效,仅保持向后兼容(Ineffective, only kept for backward compatibility)
    -V,--show-version 显示版本信息,不会停止编译(Display version information WITHOUT stopping build)
    -v,--version 显示版本信息Display version information
    -X,--debug 输出执行的debug信息(Produce execution debug output)


猜你喜欢

转载自liyghting.iteye.com/blog/2337983