当前位置:首页 > 开发 > 开源软件 > 正文

[Maven学习笔记二]Maven命令

发表于: 2014-08-02   作者:bit1129   来源:转载   浏览:
摘要: mvn compile compile编译命令将src/main/java和src/main/resources中的代码和配置文件编译到target/classes中,不会对src/test/java中的测试类进行编译 MVN编译使用 maven-resources-plugin:2.6:resources maven-compiler-plugin:2.5.1:compile &nbs

mvn compile

compile编译命令将src/main/java和src/main/resources中的代码和配置文件编译到target/classes中,不会对src/test/java中的测试类进行编译

MVN编译使用

maven-resources-plugin:2.6:resources

maven-compiler-plugin:2.5.1:compile

 

mvn test

test命令首先将src/test/java中的测试代码编译到target/test-classes中,然后执行target/test-classes中的单元测试类,将单元测试的执行结果文件保存到target/surefire-reports目录中,这些文件是junit帮助生成的,详细记录了单元测试的类,方法以及单元测试失败的异常信息

mvn测试命令使用

maven-resources-plugin:2.6:testResources

maven-compiler-plugin:2.5.1:compile

maven-surefire-plugin:2.12.4:test

 

mvn clean

mvn compile采取增量编译的方式,如果classes目录下已经编译过某个类或者单元测试类,而此时这些类没有变化,那么mvn compile不会重新编译这些类,那么如果让这些类重新编译,需要将target/classes,target/test-classes目录下的类清除,这就是mvn clean的工作。它使用maven-clean-plugin:2.5 clean执行clean操作,操作结果如下:

 

[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ LearnMaven ---
[INFO] Deleting /home/tom/development/learnmaven/maven-ch01/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.837 s
[INFO] Finished at: 2014-08-02T08:22:40+08:00
[INFO] Final Memory: 9M/108M
[INFO] -----------------------------------------------------------------------

 

mvn package

 mvn package包含了编译的步骤,它是将

1. 将src/main/java中的代码编译到target/classes路径下

2. 将src/main/resources中的资源文件编译到target/classes路径下

3. 将src/test/java中的代码编译到target/test-classes路径下

4. 将src/test/resources中的资源文件编译到target/test-classes路径下

5. 默认打包成jar,包中不包含测试类的输出,输出信息如下

hadoop-os:~/development/learnmaven/maven-ch01$ mvn package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building LearnMaven 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ LearnMaven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ LearnMaven ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/tom/development/learnmaven/maven-ch01/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ LearnMaven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/tom/development/learnmaven/maven-ch01/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ LearnMaven ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/tom/development/learnmaven/maven-ch01/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ LearnMaven ---
[INFO] Surefire report directory: /home/tom/development/learnmaven/maven-ch01/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.tom.HelloMavenTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.109 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

 

mvn install

将Maven模块添加到本地仓库中,

hadoop-os:~/development/learnmaven/maven-ch01$ mvn install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building LearnMaven-ch01 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ LearnMaven-ch01 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ LearnMaven-ch01 ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/tom/development/learnmaven/maven-ch01/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ LearnMaven-ch01 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/tom/development/learnmaven/maven-ch01/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ LearnMaven-ch01 ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/tom/development/learnmaven/maven-ch01/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ LearnMaven-ch01 ---
[INFO] Surefire report directory: /home/tom/development/learnmaven/maven-ch01/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.tom.HelloMavenTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.106 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ LearnMaven-ch01 ---
[INFO] Building jar: /home/tom/development/learnmaven/maven-ch01/target/LearnMaven-ch01-1.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ LearnMaven-ch01 ---
[INFO] Installing /home/to/mdevelopment/learnmaven/maven-ch01/target/LearnMaven-ch01-1.0.jar to /home/tom/.m2/repository/LearnMaven/LearnMaven-ch01/1.0/LearnMaven-ch01-1.0.jar
[INFO] Installing /home/tom/development/learnmaven/maven-ch01/pom.xml to /home/tom/.m2/repository/LearnMaven/LearnMaven-ch01/1.0/LearnMaven-ch01-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.464 s
[INFO] Finished at: 2014-08-02T09:26:51+08:00
[INFO] Final Memory: 15M/169M
[INFO] ------------------------------------------------------------------------

 

 

 

 

 

 

[Maven学习笔记二]Maven命令

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
maven常用的命令 mvn archetype:create 创建Maven项目 mvn compile 编译源代码 mvn deploy 发布项
在Windows上安装Maven: 1. 首先检查安装JDK 通过命令行运行命令: echo %JAVA_HOME%和 java -versi
在Windows上安装Maven: 1. 首先检查JDK安装 通过命令行执行命令: echo %JAVA_HOME%和 java -versi
前言 上篇blog介绍了maven最基础的一些核心概念,包括maven项目约定的目录结构、maven核心配置文件
前言 上篇blog学习了Maven的下载与安装,有了家伙就可以放手去干活了,所以本篇blog我们开始学习Mav
Maven学习笔记二:设置HTTP代理 对于许多因为安全等方面因素考虑而不能随意访问外网的局域网PC则无
1.仓库布局 任何一个构件都有其唯一的坐标,根据这个坐标可以定义其在仓库中的唯一存储路径,这就是
二、Maven目录结构 bin目录-maven命令的执行命令,包括mvn和mvnDebug目录; boot目录-包含一个负责
当某些jar文件在maven镜像库中无法找到时就要创建本地maven库,以使用本地jar文件。 例:fastdfs-cl
1.安装和配置   去maven官网下载,这里用的是3.1的版本。然后解压。我这里是D:\Java\IDE\apache-m
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号