1.Maven优势
C:\Users\chj03>F:F:\>cd mavenDemoF:\mavenDemo> //cls清屏 ;dir <path>列出path路径下的文件及目录 ;// maven从官网下载项目骨架目录F:\mavenDemo>mvn archetype:generate //与用户交互式创建maven项目[INFO]Scanningfor projects......Choose a number or apply filter (format:[groupId:]artifactId,case sensitive contains):777: //通过maven-archetype-quickstart(777)创建普通的maven项目,这是默认的Choose org.apache.maven.archetypes:maven-archetype-quickstart version://选择maven-archetype-quickstart version的版本,直接回车,1:1.0-alpha-12:1.0-alpha-23:1.0-alpha-34:1.0-alpha-45:1.06:1.1Choose a number:6://回车...Define value for property ‘groupId‘:: com.chenjun.demo //组织名称Define value for property ‘artifactId‘:: maven-01 //项目名称Define value for property ‘version‘:1.0-SNAPSHOT::1.0-SNAPSHOT //版本号Define value for property ‘package‘: com.chenjun.demo:: com.chenjun.demo //包的路径Confirm properties configuration: //确认上述输入是否正确,确定无误输入Y并回车groupId: com.chenjun.demoartifactId: maven-01version:1.0-SNAPSHOTpackage: com.chenjun.demo Y:: Y[INFO]----------------------------------------------------------------------------[INFO]Using following parameters for creating project from Old(1.x)Archetype: maven-archetype-quickstart:1.1[INFO]----------------------------------------------------------------------------[INFO]Parameter: groupId,Value: com.chenjun.demo[INFO]Parameter: packageName,Value: com.chenjun.demo[INFO]Parameter: package,Value: com.chenjun.demo[INFO]Parameter: artifactId,Value: maven-01[INFO]Parameter: basedir,Value: F:\mavenDemo[INFO]Parameter: version,Value:1.0-SNAPSHOT[INFO] project created from Old(1.x)Archetypein dir: F:\mavenDemo\maven-01[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS //表示创建成功[INFO]------------------------------------------------------------------------[INFO]Total time:59:57 min[INFO]Finished at:2016-05-13T12:27:21+08:00[INFO]FinalMemory:12M/129M[INFO]------------------------------------------------------------------------//骨架目录结构不通过远程创建,通过插件内部目录结构创建,快速F:\mavenDemo\train>mvn archetype:generate -DarchetypeCatalog=internal //走本地骨架的目录[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]BuildingMavenStubProject(No POM)1[INFO]------------------------------------------------------------------------[INFO][INFO]>>> maven-archetype-plugin:2.4:generate (default-cli)> generate-sources @ standalone-pom >>>[INFO][INFO]<<< maven-archetype-plugin:2.4:generate (default-cli)< generate-sources @ standalone-pom <<<[INFO][INFO]--- maven-archetype-plugin:2.4:generate (default-cli)@ standalone-pom ---[INFO]Generating project inInteractive mode[INFO]No archetype defined.Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)Choose archetype:1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.)2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.)3: internal -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype which contains a sample Maven plugin.)4: internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (An archetype which contains a sample Maven plugin site.This archetype can be layered upon an existing Maven plugin project.)5: internal -> org.apache.maven.archetypes:maven-archetype-portlet (An archetype which contains a sample JSR-268Portlet.)6: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)8: internal -> org.apache.maven.archetypes:maven-archetype-site (An archetype which contains a sample Maven site which demonstrates some of the supported document types like APT,XDoc, and FML and demonstrates how to i18n your site.This archetype can be layered upon an existing Maven project.)9: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (An archetype which contains a sample Maven site.)10: internal -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype which contains a sample MavenWebapp project.)Choose a number or apply filter (format:[groupId:]artifactId,case sensitive contains):7: //默认,回车Define value for property ‘groupId‘:: com.sohu.train //组织名称Define value for property ‘artifactId‘:: maven-01 //项目名称Define value for property ‘version‘:1.0-SNAPSHOT::1.0-SNAPSHOT //版本号Define value for property ‘package‘: com.sohu.train:: com.sohu.train //包的路径Confirm properties configuration:groupId: com.sohu.trainartifactId: maven-01version:1.0-SNAPSHOTpackage: com.sohu.train Y:: Y[INFO]----------------------------------------------------------------------------[INFO]Using following parameters for creating project from Old(1.x)Archetype: maven-archetype-quickstart:1.1[INFO]----------------------------------------------------------------------------[INFO]Parameter: groupId,Value: com.sohu.train [INFO]Parameter: packageName,Value: com.sohu.train [INFO]Parameter: package,Value: com.sohu.train[INFO]Parameter: artifactId,Value: maven-01[INFO]Parameter: basedir,Value: F:\mavenDemo\train[INFO]Parameter: version,Value:1.0-SNAPSHOT[INFO] project created from Old(1.x)Archetypein dir: F:\mavenDemo\train\maven-01[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS //创建成功[INFO]------------------------------------------------------------------------[INFO]Total time:01:34 min[INFO]Finished at:2016-05-13T12:48:39+08:00[INFO]FinalMemory:13M/154M[INFO]------------------------------------------------------------------------F:\mavenDemo\train>tree //TREE卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.└─maven-01 //maven项目└─src├─main│└─java│└─com│└─sohu│└─train└─test└─java└─com└─sohu└─trainF:\mavenDemo\train>mvn archetype:generate -DarchetypeCatalog=internal -DgroupId=com.sohu.train -DartifactId=maven-02-Dversion=1.0-SNAPSHOT -Dpackage=com.sohu.train[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]BuildingMavenStubProject(No POM)1[INFO]------------------------------------------------------------------------[INFO][INFO]>>> maven-archetype-plugin:2.4:generate (default-cli)> generate-sources @ standalone-pom >>>[INFO][INFO]<<< maven-archetype-plugin:2.4:generate (default-cli)< generate-sources @ standalone-pom <<<[INFO][INFO]--- maven-archetype-plugin:2.4:generate (default-cli)@ standalone-pom ---[INFO]Generating project inInteractive mode[INFO]No archetype defined.Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)Choose archetype:1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.)2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.)3: internal -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype which contains a sample Maven plugin.)4: internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (An archetype which contains a sample Maven plugin site.This archetype can be layered upon an existing Maven plugin project.)5: internal -> org.apache.maven.archetypes:maven-archetype-portlet (An archetype which contains a sample JSR-268Portlet.)6: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)8: internal -> org.apache.maven.archetypes:maven-archetype-site (An archetype which contains a sample Maven site which demonstrates some of the supported document types like APT,XDoc, and FML and demonstrates how to i18n your site.This archetype can be layered upon an existing Maven project.)9: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (An archetype which contains a sample Maven site.)10: internal -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype which contains a sample MavenWebapp project.)Choose a number or apply filter (format:[groupId:]artifactId,case sensitive contains):7: //使用第7个模板创建maven项目,默认,回车[INFO]Using property: groupId = com.sohu.train[INFO]Using property: artifactId = maven-02[INFO]Using property: version =1.0-SNAPSHOT[INFO]Using property: package = com.sohu.trainConfirm properties configuration:groupId: com.sohu.trainartifactId: maven-02version:1.0-SNAPSHOTpackage: com.sohu.train Y:: Y //确认[INFO]----------------------------------------------------------------------------[INFO]Using following parameters for creating project from Old(1.x)Archetype: maven-archetype-quickstart:1.1[INFO]----------------------------------------------------------------------------[INFO]Parameter: groupId,Value: com.sohu.train[INFO]Parameter: packageName,Value: com.sohu.train[INFO]Parameter: package,Value: com.sohu.train[INFO]Parameter: artifactId,Value: maven-02[INFO]Parameter: basedir,Value: F:\mavenDemo\train[INFO]Parameter: version,Value:1.0-SNAPSHOT[INFO] project created from Old(1.x)Archetypein dir: F:\mavenDemo\train\maven-02[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS //创建成功[INFO]------------------------------------------------------------------------[INFO]Total time:33.704 s[INFO]Finished at:2016-05-13T13:02:49+08:00[INFO]FinalMemory:13M/154M[INFO]------------------------------------------------------------------------F:\mavenDemo\train>TREE卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.├─maven-01│└─src│├─main││└─java││└─com││└─sohu││└─train│└─test│└─java│└─com│└─sohu│└─train└─maven-02 //发现多了一个maven项目└─src├─main│└─java│└─com│└─sohu│└─train└─test└─java└─com└─sohu└─trainmvn archetype:generate //构建项目mvn clean //项目清理,删除target(编译好的字节码文件和测试报告)mvn compile //项目源代码的编译mvn test //项目单元测试的编译mvn package //项目打包F:\mavenDemo\train\maven-01>tree /f //查看当前目录下的项目结构卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│ pom.xml│└─src├─main│└─java│└─com│└─sohu│└─train│App.java //源文件│└─test└─java└─com└─sohu└─trainAppTest.java //单元测试文件F:\mavenDemo\train\maven-01>mvn compile[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]Building maven-011.0-SNAPSHOT[INFO]------------------------------------------------------------------------[INFO][INFO]--- maven-resources-plugin:2.6:resources (default-resources)@ maven-01---...[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\classes //完成了对一个源文件的编译,编译好的文件所在的目录[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time:13.545 s[INFO]Finished at:2016-05-13T13:27:11+08:00[INFO]FinalMemory:12M/124M[INFO]------------------------------------------------------------------------F:\mavenDemo\train\maven-01>tree /f卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│ pom.xml│├─src│├─main││└─java││└─com││└─sohu││└─train││App.java│││└─test│└─java│└─com│└─sohu│└─train│AppTest.java│└─target //发现多个一个target文件夹...//target [‘tɑ?g?t]:目标├─classes│└─com│└─sohu│└─train│App.class //对源代码文件(App.java)编译后的文件│└─maven-status└─maven-compiler-plugin //使用到的maven插件└─compile└─default-compile createdFiles.lst inputFiles.lstF:\mavenDemo\train\maven-01>mvn clean //对之前编译过的文件进行清除[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]Building maven-011.0-SNAPSHOT[INFO]------------------------------------------------------------------------[INFO][INFO]--- maven-clean-plugin:2.5:clean (default-clean)@ maven-01---[INFO]Deleting F:\mavenDemo\train\maven-01\target[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time:0.441 s[INFO]Finished at:2016-05-13T13:36:47+08:00[INFO]FinalMemory:6M/121M[INFO]------------------------------------------------------------------------F:\mavenDemo\train\maven-01>tree /f //target文件夹已经被清除卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│ pom.xml│└─src├─main│└─java│└─com│└─sohu│└─train│App.java│└─test└─java└─com└─sohu└─trainAppTest.javaF:\mavenDemo\train\maven-01>mvn test[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]Building maven-011.0-SNAPSHOT[INFO]------------------------------------------------------------------------...[INFO][INFO]--- maven-resources-plugin:2.6:resources (default-resources)@ maven-01---[INFO]Using‘UTF-8‘ encoding to copy filtered resources.[INFO] skip non existing resourceDirectory F:\mavenDemo\train\maven-01\src\main\resources[INFO][INFO]--- maven-compiler-plugin:3.1:compile (default-compile)@ maven-01---[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\classes[INFO][INFO]--- maven-resources-plugin:2.6:testResources (default-testResources)@ maven-01---[INFO]Using‘UTF-8‘ encoding to copy filtered resources.[INFO] skip non existing resourceDirectory F:\mavenDemo\train\maven-01\src\test\resources[INFO][INFO]--- maven-compiler-plugin:3.1:testCompile (default-testCompile)@ maven-01---[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\test-classes[INFO][INFO]--- maven-surefire-plugin:2.12.4:test (default-test)@ maven-01---...------------------------------------------------------- T E S T S-------------------------------------------------------Running com.sohu.train.AppTestTests run:1,Failures:0,Errors:0,Skipped:0,Time elapsed:0.007 secResults:Tests run:1,Failures:0,Errors:0,Skipped:0[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time:20.556 s[INFO]Finished at:2016-05-13T13:41:16+08:00[INFO]FinalMemory:15M/160M[INFO]------------------------------------------------------------------------F:\mavenDemo\train\maven-01>tree /f卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│ pom.xml│├─src│├─main││└─java││└─com││└─sohu││└─train││App.java│││└─test│└─java│└─com│└─sohu│└─train│AppTest.java│└─target //生成一个target目录,并未执行 mvn compile 命令├─classes│└─com│└─sohu│└─train│App.class│├─maven-status│└─maven-compiler-plugin //用到的插件│├─compile││└─default-compile││ createdFiles.lst││ inputFiles.lst│││└─testCompile│└─default-testCompile│ createdFiles.lst│ inputFiles.lst│├─surefire-reports //单元测试生成的报告│ com.sohu.train.AppTest.txt│ TEST-com.sohu.train.AppTest.xml│└─test-classes //完成单元测试的编译,即编译AppTest.java文件└─com└─sohu└─trainAppTest.classF:\mavenDemo\train\maven-01>mvn package[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]Building maven-011.0-SNAPSHOT[INFO]------------------------------------------------------------------------[INFO][INFO]--- maven-resources-plugin:2.6:resources (default-resources)@ maven-01---[INFO]Using‘UTF-8‘ encoding to copy filtered resources.[INFO] skip non existing resourceDirectory F:\mavenDemo\train\maven-01\src\main\resources[INFO][INFO]--- maven-compiler-plugin:3.1:compile (default-compile)@ maven-01---[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\classes[INFO][INFO]--- maven-resources-plugin:2.6:testResources (default-testResources)@ maven-01---[INFO]Using‘UTF-8‘ encoding to copy filtered resources.[INFO] skip non existing resourceDirectory F:\mavenDemo\train\maven-01\src\test\resources[INFO][INFO]--- maven-compiler-plugin:3.1:testCompile (default-testCompile)@ maven-01---[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\test-classes[INFO][INFO]--- maven-surefire-plugin:2.12.4:test (default-test)@ maven-01---[INFO]Surefire report directory: F:\mavenDemo\train\maven-01\target\surefire-reports------------------------------------------------------- T E S T S-------------------------------------------------------Running com.sohu.train.AppTestTests run:1,Failures:0,Errors:0,Skipped:0,Time elapsed:0.007 secResults:Tests run:1,Failures:0,Errors:0,Skipped:0[INFO][INFO]--- maven-jar-plugin:2.4:jar (default-jar)@ maven-01---Downloading: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jarDownloaded: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar(37 KB at 17.7 KB/sec)[INFO]Building jar: F:\mavenDemo\train\maven-01\target\maven-01-1.0-SNAPSHOT.jar[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time:5.625 s[INFO]Finished at:2016-05-13T13:52:43+08:00[INFO]FinalMemory:19M/225M[INFO]------------------------------------------------------------------------F:\mavenDemo\train\maven-01>tree /f卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│ pom.xml│├─src│├─main││└─java││└─com││└─sohu││└─train││App.java│││└─test│└─java│└─com│└─sohu│└─train│AppTest.java│└─target │ maven-01-1.0-SNAPSHOT.jar //生成jar包.;创建maven项目的时候约定的一个规则,maven-01是定义好的项目名称,1.0-SNAPSHOT是定义好的版本号;│├─classes│└─com│└─sohu│└─train│App.class│├─maven-archiver│ pom.properties│├─maven-status│└─maven-compiler-plugin│├─compile││└─default-compile││ createdFiles.lst││ inputFiles.lst│││└─testCompile│└─default-testCompile│ createdFiles.lst│ inputFiles.lst│├─surefire-reports│ com.sohu.train.AppTest.txt│ TEST-com.sohu.train.AppTest.xml│└─test-classes└─com└─sohu└─trainAppTest.classF:\mavenDemo\train\maven-01>tree /f卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│.classpath│.project│ pom.xml│├─.settings│ org.eclipse.core.resources.prefs│ org.eclipse.jdt.core.prefs│ org.eclipse.m2e.core.prefs│└─src├─main│└─java│└─com│└─sohu│└─train│App.java│└─test└─java└─com└─sohu└─trainAppTest.javaF:\mavenDemo\train\maven-01>mvn install[INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]Building maven-011.0-SNAPSHOT[INFO]------------------------------------------------------------------------[INFO][INFO]--- maven-resources-plugin:2.6:resources (default-resources)@ maven-01---[INFO]Using‘UTF-8‘ encoding to copy filtered resources.[INFO] skip non existing resourceDirectory F:\mavenDemo\train\maven-01\src\main\resources[INFO][INFO]--- maven-compiler-plugin:3.1:compile (default-compile)@ maven-01---[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\classes[INFO][INFO]--- maven-resources-plugin:2.6:testResources (default-testResources)@ maven-01---[INFO]Using‘UTF-8‘ encoding to copy filtered resources.[INFO] skip non existing resourceDirectory F:\mavenDemo\train\maven-01\src\test\resources[INFO][INFO]--- maven-compiler-plugin:3.1:testCompile (default-testCompile)@ maven-01---[INFO]Changes detected - recompiling the module![INFO]Compiling1 source file to F:\mavenDemo\train\maven-01\target\test-classes[INFO][INFO]--- maven-surefire-plugin:2.12.4:test (default-test)@ maven-01---[INFO]Surefire report directory: F:\mavenDemo\train\maven-01\target\surefire-reports------------------------------------------------------- T E S T S-------------------------------------------------------Running com.sohu.train.AppTestTests run:1,Failures:0,Errors:0,Skipped:0,Time elapsed:0.011 secResults:Tests run:1,Failures:0,Errors:0,Skipped:0[INFO][INFO]--- maven-jar-plugin:2.4:jar (default-jar)@ maven-01---[INFO]Building jar: F:\mavenDemo\train\maven-01\target\maven-01-1.0-SNAPSHOT.jar[INFO][INFO]--- maven-install-plugin:2.4:install (default-install)@ maven-01---[INFO]Installing F:\mavenDemo\train\maven-01\target\maven-01-1.0-SNAPSHOT.jar to E:\mavenRepository\com\sohu\train\maven-01\1.0-SNAPSHOT\maven-01-1.0-SNAPSHOT.jar //安装jar包到本地仓库[INFO]Installing F:\mavenDemo\train\maven-01\pom.xml to E:\mavenRepository\com\sohu\train\maven-01\1.0-SNAPSHOT\maven-01-1.0-SNAPSHOT.pom[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time:3.429 s[INFO]Finished at:2016-05-13T23:07:51+08:00[INFO]FinalMemory:14M/225M[INFO]------------------------------------------------------------------------F:\mavenDemo\train\maven-01>tree /f卷Spark的文件夹 PATH 列表卷序列号为0007-FD09F:.│.classpath│.project│ pom.xml│├─.settings│ org.eclipse.core.resources.prefs│ org.eclipse.jdt.core.prefs│ org.eclipse.m2e.core.prefs│├─src│├─main││└─java││└─com││└─sohu││└─train││App.java│││└─test│└─java│└─com│└─sohu│└─train│AppTest.java│└─target│ maven-01-1.0-SNAPSHOT.jar│├─classes│└─com│└─sohu│└─train│App.class│├─maven-archiver│ pom.properties│├─maven-status│└─maven-compiler-plugin│├─compile││└─default-compile││ createdFiles.lst││ inputFiles.lst│││└─testCompile│└─default-testCompile│ createdFiles.lst│ inputFiles.lst│├─surefire-reports│ com.sohu.train.AppTest.txt│ TEST-com.sohu.train.AppTest.xml│└─test-classes└─com└─sohu└─trainAppTest.class原文:http://www.cnblogs.com/chj0911/p/5500998.html