[Maven学习笔记二]Maven命令

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)