微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Maven的第一个小程序

这里是介绍关于maven的第一个小程序

关于maven的安装 :

先看看目录结构:

这是本来的项目目录结构,由于maven有自己的目录结构,所以,下面的是加入maven元素后的目录结构:

即:

文件要和src目录在同一级

NOTE:

你所看到的有红色X标示错误提示,这是在Eclipse中的提示,这个可以不用理会。

接下来才是关键:

4.0.0 com.b510.maven.hello hello-first SNAPSHOT-0.0.1 junit junit 4.10 copetestcope

pom.xml文件,是project object manager的首字母缩写。即项目对象管理。

在pom.xml文件中,对于我们写的com.b510.maven.hello.Hello.java类,他的groupId = com.b510.maven.hello,artifactId = hello-first,version = SNAPSHOT-0.0.1

而我们的测试类,所依赖的包为junit,它属于test域。

下面是Hello类和HelloTest类

System.out.println("This is a test message!" String str = Hello().sayHello("Hongten",20 stem.out.println(str); String sayHello(String name, "I'm " + name + ",I'm " + age + ",Hello" }

org.junit.Assert.* Hello hello = assertEquals(hello.sayHello("Hongten",20),"I'm Hongten,I'm 20,Hello" }

两个类都是很简单的类。

现在我们启动windows的控制台。即运行--> cmd,或Ctrl+R --> cmd

进入到项目的根目录:D:\Development\workspace\maven_project  

由于我们本地仓库中没有编译所需要的资源,所有,maven会到远程仓库中去获取资源到本地

下面是控制台运行效果:这里只是截取了部分log

Downloading: http: arameter-documenter/2.0.6/maven-plugin-parameter-documenter-2.0.6 Downloaded: http: rameter-documenter/2.0.6/maven-plugin-parameter-documenter-2.0.6.pom (2 KB at 3 8 KB/ Downloading: http: n-reporting-api/2.0.6/maven-reporting-api-2.0.6 Downloaded: http: -reporting-api/2.0.6/maven-reporting-api-2.0.6.pom (2 KB at 3.8 KB/ Downloading: http: n-reporting/2.0.6/maven-reporting-2.0.6 Downloaded: http: -reporting/2.0.6/maven-reporting-2.0.6.pom (2 KB at 3.2 KB/ Downloading: http: nk-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7 Downloaded: http: k-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.pom (424 B at 0.9 KB/ Downloading: http: 0-alpha-7/doxia-1.0-alpha-7 Downloaded: http: -alpha-7/doxia-1.0-alpha-7.pom (4 KB at 8.4 KB/ Downloading: http: agnostics/2.0.6/maven-error-diagnostics-2.0.6 Downloaded: http: gnostics/2.0.6/maven-error-diagnostics-2.0.6.pom (2 KB at 3.3 KB/ Downloading: http: mons-cli-1.0 Downloaded: http: ons-cli-1.0.pom (3 KB at 4.4 KB/ Downloading: http: escriptor/2.0.6/maven-plugin-descriptor-2.0.6 Downloaded: http: scriptor/2.0.6/maven-plugin-descriptor-2.0.6.pom (2 KB at 4.0 KB/ Downloading: http: ractivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4 Downloaded: http: activity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.pom (7 KB at 13.6 KB/ Downloading: http: 2.0.6/maven-monitor-2.0.6 Downloaded: http: .0.6/maven-monitor-2.0.6.pom (2 KB at 2.4 KB/ Downloading: http: ssworlds-1.1 Downloaded: http: sworlds-1.1.pom (4 KB at 6.7 KB/ Downloading: http: s/2.0.5/plexus-utils-2.0.5 Downloaded: http: /2.0.5/plexus-utils-2.0.5.pom (4 KB at 6.6 KB/ Downloading: http: 6/plexus-2.0.6 Downloaded: http: /plexus-2.0.6.pom (17 KB at 21.9 KB/ Downloading: http: iltering/1.1/maven-filtering-1.1 Downloaded: http: ltering/1.1/maven-filtering-1.1.pom (6 KB at 11.5 KB/ Downloading: http: hared-components/17/maven-shared-components-17 Downloaded: http: ared-components/17/maven-shared-components-17.pom (9 KB at 15.3 KB/ Downloading: http: s/1.5.15/plexus-utils-1.5.15 Downloaded: http: /1.5.15/plexus-utils-1.5.15.pom (7 KB at 8.1 KB/ Downloading: http: 2/plexus-2.0.2 Downloaded: http: /plexus-2.0.2.pom (12 KB at 13.9 KB/ Downloading: http: rpolation/1.12/plexus-interpolation-1.12 Downloaded: http: polation/1.12/plexus-interpolation-1.12.pom (889 B at 1.5 KB/ Downloading: http: onents/1.1.14/plexus-components-1.1.14 Downloaded: http: nents/1.1.14/plexus-components-1.1.14.pom (6 KB at 10.1 KB/ Downloading: http: d-api/0.0.4/plexus-build-api-0.0.4 Downloaded: http: -api/0.0.4/plexus-build-api-0.0.4.pom (3 KB at 4.7 KB/ Downloading: http: /10/spice-parent-10 Downloaded: http: 10/spice-parent-10.pom (3 KB at 5.3 KB/ Downloading: http: /3/forge-parent-3 Downloaded: http: 3/forge-parent-3.pom (5 KB at 8.6 KB/ Downloading: http: s/1.5.8/plexus-utils-1.5.8 Downloaded: http: /1.5.8/plexus-utils-1.5.8.pom (8 KB at 13.4 KB/ Downloading: http: rpolation/1.13/plexus-interpolation-1.13 Downloaded: http: polation/1.13/plexus-interpolation-1.13.pom (890 B at 1.4 KB/ Downloading: http: onents/1.1.15/plexus-components-1.1.15 Downloaded: http: nents/1.1.15/plexus-components-1.1.15.pom (3 KB at 4.2 KB/ Downloading: http: 3/plexus-2.0.3 Downloaded: http: /plexus-2.0.3.pom (16 KB at 17.3 KB/ Downloading: http: nk-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7 Downloading: http: ractivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4 Downloading: http: Downloading: http: mons-cli-1.0 Downloading: http: n-reporting-api/2.0.6/maven-reporting-api-2.0.6 Downloaded: http: k-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar (6 KB at 10.5 KB/ Downloading: http: s/2.0.5/plexus-utils-2.0.5 Downloaded: http: -reporting-api/2.0.6/maven-reporting-api-2.0.6.jar (10 KB at 11.1 KB/ Downloading: http: iltering/1.1/maven-filtering-1.1 Downloaded: http: ons-cli-1.0.jar (30 KB at 27.5 KB/ Downloading: http: d-api/0.0.4/plexus-build-api-0.0.4 Downloaded: http: activity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar (14 KB at 10.4 KB/ Downloading: http: rpolation/1.13/plexus-interpolation-1.13 Downloaded: http: r (119 KB at 73.9 KB/ Downloaded: http: -api/0.0.4/plexus-build-api-0.0.4.jar (7 KB at 11.8 KB/ Downloaded: http: ltering/1.1/maven-filtering-1.1.jar (43 KB at 38.9 KB/ Downloaded: http: /2.0.5/plexus-utils-2.0.5.jar (218 KB at 91.8 KB/ Downloaded: http: polation/1.13/plexus-interpolation-1.13.jar (60 KB at 28.9 KB/ copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:compile (-compile) @ hello-first - -- Downloading: http: pi/2.0.9/maven-plugin-api-2.0.9 Downloaded: http: i/2.0.9/maven-plugin-api-2.0.9.pom (2 KB at 3.1 KB/ Downloading: http: ven-2.0.9 Downloaded: http: en-2.0.9.pom (19 KB at 26.6 KB/ Downloading: http: /maven-parent-8 Downloaded: http: maven-parent-8.pom (24 KB at 34.4 KB/ Downloading: http: Downloaded: http: (5 KB at 9.5 KB/ Downloading: http: /2.0.9/maven-artifact-2.0.9 Downloaded: http: 2.0.9/maven-artifact-2.0.9.pom (2 KB at 3.4 KB/ Downloading: http: s/1.5.1/plexus-utils-1.5.1 Downloaded: http: /1.5.1/plexus-utils-1.5.1.pom (3 KB at 4.8 KB/ Downloading: http: .9/maven-core-2.0.9 Downloaded: http: 9/maven-core-2.0.9.pom (8 KB at 11.0 KB/ Downloading: http: /2.0.9/maven-settings-2.0.9 Downloaded: http: 2.0.9/maven-settings-2.0.9.pom (3 KB at 4.2 KB/ Downloading: http: 0.9/maven-model-2.0.9 Downloaded: http: .9/maven-model-2.0.9.pom (4 KB at 6.5 KB/ Downloading: http: arameter-documenter/2.0.9/maven-plugin-parameter-documenter-2.0.9 Downloaded: http: rameter-documenter/2.0.9/maven-plugin-parameter-documenter-2.0.9.pom (2 KB at 4 2 KB/ Downloading: http: 2.0.9/maven-profile-2.0.9 Downloaded: http: .0.9/maven-profile-2.0.9.pom (3 KB at 4.2 KB/ Downloading: http: ry-Metadata/2.0.9/maven-repository-Metadata-2.0.9 Downloaded: http: y-Metadata/2.0.9/maven-repository-Metadata-2.0.9.pom (2 KB at 3.9 KB/ Downloading: http: agnostics/2.0.9/maven-error-diagnostics-2.0.9 Downloaded: http: gnostics/2.0.9/maven-error-diagnostics-2.0.9.pom (2 KB at 3.6 KB/ Downloading: http: 2.0.9/maven-project-2.0.9 Downloaded: http: .0.9/maven-project-2.0.9.pom (3 KB at 5.5 KB/ Downloading: http: -manager/2.0.9/maven-artifact-manager-2.0.9 Downloaded: http: manager/2.0.9/maven-artifact-manager-2.0.9.pom (3 KB at 5.2 KB/ Downloading: http: egistry/2.0.9/maven-plugin-registry-2.0.9 Downloaded: http: gistry/2.0.9/maven-plugin-registry-2.0.9.pom (2 KB at 3.8 KB/ Downloading: http: escriptor/2.0.9/maven-plugin-descriptor-2.0.9 Downloaded: http: scriptor/2.0.9/maven-plugin-descriptor-2.0.9.pom (3 KB at 3.9 KB/ Downloading: http: 2.0.9/maven-monitor-2.0.9 Downloaded: http: .0.9/maven-monitor-2.0.9.pom (2 KB at 2.5 KB/ Downloading: http: n/1.0/maven-toolchain-1.0 Downloaded: http: /1.0/maven-toolchain-1.0.pom (4 KB at 6.3 KB/ Downloading: http: s/3.0/plexus-utils-3.0 Downloaded: http: /3.0/plexus-utils-3.0.pom (4 KB at 7.8 KB/ Downloading: http: /16/spice-parent-16 Downloaded: http: 16/spice-parent-16.pom (9 KB at 16.7 KB/ Downloading: http: /5/forge-parent-5 Downloaded: http: 5/forge-parent-5.pom (9 KB at 15.8 KB/ Downloading: http: iler-api/1.9.1/plexus-compiler-api-1.9.1 Downloaded: http: ler-api/1.9.1/plexus-compiler-api-1.9.1.pom (867 B at 1.8 KB/ Downloading: http: iler/1.9.1/plexus-compiler-1.9.1 Downloaded: http: ler/1.9.1/plexus-compiler-1.9.1.pom (4 KB at 7.8 KB/ Downloading: http: onents/1.1.20/plexus-components-1.1.20 Downloaded: http: nents/1.1.20/plexus-components-1.1.20.pom (3 KB at 6.0 KB/ Downloading: http: plexus-3.1 Downloaded: http: lexus-3.1.pom (19 KB at 26.7 KB/ Downloading: http: /17/spice-parent-17 Downloaded: http: 17/spice-parent-17.pom (7 KB at 13.9 KB/ Downloading: http: /10/forge-parent-10 Downloaded: http: 10/forge-parent-10.pom (14 KB at 19.0 KB/ Downloading: http: iler-manager/1.9.1/plexus-compiler-manager-1.9.1 Downloaded: http: ler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom (692 B at 1.3 KB/ Downloading: http: iler-javac/1.9.1/plexus-compiler-javac-1.9.1 Downloaded: http: ler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom (688 B at 1.4 KB/ Downloading: http: ilers/1.9.1/plexus-compilers-1.9.1 Downloaded: http: lers/1.9.1/plexus-compilers-1.9.1.pom (2 KB at 2.6 KB/ Downloading: http: s/3.0/plexus-utils-3.0 Downloading: http: iler-javac/1.9.1/plexus-compiler-javac-1.9.1 Downloading: http: iler-manager/1.9.1/plexus-compiler-manager-1.9.1 Downloading: http: iler-api/1.9.1/plexus-compiler-api-1.9.1 Downloaded: http: ler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar (5 KB at 6.3 KB/ Downloaded: http: ler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar (14 KB at 15.0 KB/ Downloaded: http: ler-api/1.9.1/plexus-compiler-api-1.9.1.jar (21 KB at 22.5 KB/ Downloaded: http: /3.0/plexus-utils-3.0.jar (221 KB at 89.4 KB/ [INFO] nothing to compile - [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:06 [INFO] Finished at: 2014-07-06T10:39:32+08:00 [INFO] Final Memory: 3M/ [INFO] ------------------------------------------------------------------------ D:\Development\workspace\maven_project>

我们看到maven执行了命令,并且从远程仓库下载了资源进行对项目进行编译,最后成功了。

这些远程资源会下载到我们电脑的:C:\Users\Administrator\.m2\repository  目录下面

然而,当我们的本地仓库中已经有了这些资源,在第二次执行上面的命令的时候,就不会到远程仓库中去获取资源,而是直接到本地仓库中获取

下面是再次执行上面的命令:

Microsoft Windows [版本 6.1.7601 版权所有 (c) 2009 C:\Users\Administrator> D:\> D:\Development\workspace\maven_project> [INFO] Scanning [INFO] ------------------------------------------------------------------------ [INFO] Building hello-first SNAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ [INFO] --- maven-resources-plugin:2.6:resources (-resources) @ hello-irs t --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:compile (-compile) @ hello-first - -- [INFO] nothing to compile - [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.699 [INFO] Finished at: 2014-07-06T10:45:33+08:00 [INFO] Final Memory: 3M/ [INFO] ------------------------------------------------------------------------ D:\Development\workspace\maven_project>

D:\Development\workspace\maven_project> [INFO] Scanning [INFO] ------------------------------------------------------------------------ [INFO] Building hello-first SNAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ Downloading: http: surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4 Downloaded: http: urefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom (11 KB at 12.7 KB/ Downloading: http: ire/2.12.4/surefire-2.12.4 Downloaded: http: re/2.12.4/surefire-2.12.4.pom (14 KB at 29.1 KB/ Downloading: http: surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4 Downloaded: http: urefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar (30 KB at 33.1 KB/ Downloading: http: Downloading: http: hamcrest-core-1.1 Downloaded: http: amcrest-core-1.1.jar (75 KB at 48.7 KB/ Downloaded: http: (248 KB at 114.4 KB/ [INFO] --- maven-resources-plugin:2.6:resources (-resources) @ hello-irs t --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:compile (-compile) @ hello-first - -- [INFO] nothing to compile - [INFO] --- maven-resources-plugin:2.6:testResources (- llo-first --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:testCompile (- -first --- [INFO] nothing to compile - [INFO] --- maven-surefire-plugin:2.12.4:test (-test) @ hello-first --- Downloading: http: ire-booter/2.12.4/surefire-booter-2.12.4 Downloaded: http: re-booter/2.12.4/surefire-booter-2.12.4.pom (3 KB at 6.2 KB/ Downloading: http: ire-api/2.12.4/surefire-api-2.12.4 Downloaded: http: re-api/2.12.4/surefire-api-2.12.4.pom (3 KB at 5.2 KB/ Downloading: http: -surefire-common/2.12.4/maven-surefire-common-2.12.4 Downloaded: http: surefire-common/2.12.4/maven-surefire-common-2.12.4.pom (6 KB at 11.1 KB/ Downloading: http: aven-plugin-annotations/3.1/maven-plugin-annotations-3.1 Downloaded: http: ven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom (2 KB at 3.4 KB/ Downloading: http: aven-plugin-tools/3.1/maven-plugin-tools-3.1 Downloaded: http: ven-plugin-tools/3.1/maven-plugin-tools-3.1.pom (16 KB at 23.3 KB/ Downloading: http: s/3.0.8/plexus-utils-3.0.8 Downloaded: http: /3.0.8/plexus-utils-3.0.8.pom (4 KB at 6.6 KB/ Downloading: http: plexus-3.2 Downloaded: http: lexus-3.2.pom (19 KB at 25.1 KB/ Downloading: http: n-reporting-api/2.0.9/maven-reporting-api-2.0.9 Downloaded: http: -reporting-api/2.0.9/maven-reporting-api-2.0.9.pom (2 KB at 3.4 KB/ Downloading: http: n-reporting/2.0.9/maven-reporting-2.0.9 Downloaded: http: -reporting/2.0.9/maven-reporting-2.0.9.pom (2 KB at 3.0 KB/ Downloading: http: n/2.0.9/maven-toolchain-2.0.9 Downloaded: http: /2.0.9/maven-toolchain-2.0.9.pom (4 KB at 7.0 KB/ Downloading: http: 3/3.1/commons-lang3-3.1 Downloaded: http: /3.1/commons-lang3-3.1.pom (17 KB at 17.9 KB/ Downloading: http: nt/22/commons-parent-22 Downloaded: http: t/22/commons-parent-22.pom (41 KB at 31.6 KB/ Downloading: http: Downloaded: http: (15 KB at 29.1 KB/ Downloading: http: ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3 Downloaded: http: mmon-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom (4 KB at 7.8 KB/ Downloading: http: hared-components/12/maven-shared-components-12 Downloaded: http: ared-components/12/maven-shared-components-12.pom (10 KB at 13.2 KB/ Downloading: http: 3/maven-parent-13 Downloaded: http: /maven-parent-13.pom (23 KB at 32.1 KB/ Downloading: http: Downloaded: http: (13 KB at 25.5 KB/ Downloading: http: ainer-/1.0-alpha-9/plexus-container--1.0-alpha-9 Downloaded: http: iner-/1.0-alpha-9/plexus-container--1.0-alpha-9.pom (2 KB at 2.6 B/ Downloading: http: ire-booter/2.12.4/surefire-booter-2.12.4 Downloading: http: -surefire-common/2.12.4/maven-surefire-common-2.12.4 Downloading: http: ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3 Downloading: http: 3/3.1/commons-lang3-3.1 Downloading: http: ire-api/2.12.4/surefire-api-2.12.4 Downloaded: http: mmon-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar (31 KB at 34.4 B/ Downloading: http: s/3.0.8/plexus-utils-3.0.8 Downloaded: http: re-booter/2.12.4/surefire-booter-2.12.4.jar (34 KB at 31.9 KB/ Downloading: http: n-reporting-api/2.0.9/maven-reporting-api-2.0.9 Downloaded: http: re-api/2.12.4/surefire-api-2.12.4.jar (115 KB at 75.2 KB/ Downloading: http: aven-plugin-annotations/3.1/maven-plugin-annotations-3.1 Downloaded: http: -reporting-api/2.0.9/maven-reporting-api-2.0.9.jar (10 KB at 18.7 KB/ Downloaded: http: ven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar (14 KB at 28.4 KB/ Downloaded: http: /3.1/commons-lang3-3.1.jar (309 KB at 145.2 KB/ Downloaded: http: surefire-common/2.12.4/maven-surefire-common-2.12.4.jar (257 KB at 117.9 KB/ Downloaded: http: /3.0.8/plexus-utils-3.0.8.jar (227 KB at 116.0 KB/ surefire- Downloading: http: ire-junit4/2.12.4/surefire-junit4-2.12.4 Downloaded: http: re-junit4/2.12.4/surefire-junit4-2.12.4.pom (3 KB at 5.1 KB/ Downloading: http: ire-providers/2.12.4/surefire-providers-2.12.4 Downloaded: http: re-providers/2.12.4/surefire-providers-2.12.4.pom (3 KB at 4.6 KB/ Downloading: http: ire-junit4/2.12.4/surefire-junit4-2.12.4 Downloaded: http: re-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 KB at 33.0 KB/ ------------------------------------------------------- ------------------------------------------------------- Tests run: 1,Failures: 0,Errors: 0,Skipped: 0,Time elapsed: 0.038 Tests run: 1,Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] Total time: 22.319 [INFO] Finished at: 2014-07-06T10:46:53+08:00 [INFO] Final Memory: 4M/ [INFO] ------------------------------------------------------------------------ D:\Development\workspace\maven_project>

上面是进行测试用例的编译和测试

下面进行打包操作

Microsoft Windows [版本 6.1.7601 版权所有 (c) 2009 C:\Users\Administrator> D:\> D:\Development\workspace\maven_project>mvn [INFO] Scanning [INFO] ------------------------------------------------------------------------ [INFO] Building hello-first SNAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ Downloading: http: jar-plugin/2.4/maven-jar-plugin-2.4 Downloaded: http: ar-plugin/2.4/maven-jar-plugin-2.4.pom (6 KB at 3.2 KB/ Downloading: http: jar-plugin/2.4/maven-jar-plugin-2.4 Downloaded: http: ar-plugin/2.4/maven-jar-plugin-2.4.jar (34 KB at 36.3 KB/ [INFO] --- maven-resources-plugin:2.6:resources (-resources) @ hello-irs t --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:compile (-compile) @ hello-first - -- [INFO] nothing to compile - [INFO] --- maven-resources-plugin:2.6:testResources (- llo-first --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:testCompile (- -first --- [INFO] nothing to compile - [INFO] --- maven-surefire-plugin:2.12.4:test (-test) @ hello-first --- surefire- ------------------------------------------------------- ------------------------------------------------------- Tests run: 1,Time elapsed: 0.03 Tests run: 1,Skipped: 0 [INFO] --- maven-jar-plugin:2.4:jar (-jar) @ hello-first --- Downloading: http: /2.5/maven-archiver-2.5 Downloaded: http: 2.5/maven-archiver-2.5.pom (5 KB at 9.1 KB/ Downloading: http: iver/2.1/plexus-archiver-2.1 Downloaded: http: ver/2.1/plexus-archiver-2.1.pom (3 KB at 5.5 KB/ Downloading: http: .0.2/plexus-io-2.0.2 Downloaded: http: 0.2/plexus-io-2.0.2.pom (2 KB at 3.5 KB/ Downloading: http: onents/1.1.19/plexus-components-1.1.19 Downloaded: http: nents/1.1.19/plexus-components-1.1.19.pom (3 KB at 5.1 KB/ Downloading: http: 1/plexus-3.0.1 Downloaded: http: /plexus-3.0.1.pom (19 KB at 34.7 KB/ Downloading: http: rpolation/1.15/plexus-interpolation-1.15 Downloaded: http: polation/1.15/plexus-interpolation-1.15.pom (1018 B at 2.0 KB/ Downloading: http: ommons-lang-2.1 Downloaded: http: mmons-lang-2.1.pom (10 KB at 20.3 KB/ Downloading: http: /2.5/maven-archiver-2.5 Downloading: http: .0.2/plexus-io-2.0.2 Downloading: http: rpolation/1.15/plexus-interpolation-1.15 Downloading: http: iver/2.1/plexus-archiver-2.1 Downloading: http: ommons-lang-2.1 Downloaded: http: 2.5/maven-archiver-2.5.jar (22 KB at 39.7 KB/ Downloaded: http: 0.2/plexus-io-2.0.2.jar (57 KB at 54.0 KB/ Downloaded: http: polation/1.15/plexus-interpolation-1.15.jar (60 KB at 50.3 KB/ Downloaded: http: mmons-lang-2.1.jar (203 KB at 117.4 KB/ Downloaded: http: ver/2.1/plexus-archiver-2.1.jar (181 KB at 104.1 KB/ [INFO] Building jar: D:\Development\workspace\maven_project\target\hello-first- NAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.989 [INFO] Finished at: 2014-07-06T10:49:01+08:00 [INFO] Final Memory: 4M/ [INFO] ------------------------------------------------------------------------ D:\Development\workspace\maven_project>

执行命令后,我们再来看看项目的结构:

fdb0b.png" alt="" width="420" height="483">

这时候,我们发现,项目中多了target目录,这是maven生成了目录。

请注意看:hello-first-SNAPSHOT-0.0.1.jar文件,这个是根据我们在pom.xml中配置的artifactId = hello-first,version = SNAPSHOT-0.0.1所生成的。

即清除掉target目录即target目录下面的所有文件

D:\Development\workspace\maven_project> [INFO] Scanning [INFO] ------------------------------------------------------------------------ [INFO] Building hello-first SNAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ Downloading: http: clean-plugin/2.5/maven-clean-plugin-2.5 Downloaded: http: lean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 5.0 KB/ Downloading: http: clean-plugin/2.5/maven-clean-plugin-2.5 Downloaded: http: lean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 37.2 KB/ [INFO] --- maven-clean-plugin:2.5:clean (-clean) @ hello-first --- [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.066 [INFO] Finished at: 2014-07-06T10:55:13+08:00 [INFO] Final Memory: 2M/ [INFO] ------------------------------------------------------------------------ D:\Development\workspace\maven_project>

是把我们的资源加载到本地仓库中。

Microsoft Windows [版本 6.1.7601 版权所有 (c) 2009 C:\Users\Administrator> D:\> D:\Development\workspace\maven_project> [INFO] Scanning [INFO] ------------------------------------------------------------------------ [INFO] Building hello-first SNAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ Downloading: http: install-plugin/2.4/maven-install-plugin-2.4 Downloaded: http: nstall-plugin/2.4/maven-install-plugin-2.4.pom (7 KB at 3.4 KB/ Downloading: http: install-plugin/2.4/maven-install-plugin-2.4 Downloaded: http: nstall-plugin/2.4/maven-install-plugin-2.4.jar (27 KB at 37.0 KB/ [INFO] --- maven-resources-plugin:2.6:resources (-resources) @ hello-irs t --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:compile (-compile) @ hello-first - -- d is platform dependent! [INFO] Compiling 1 [INFO] --- maven-resources-plugin:2.6:testResources (- llo-first --- copy filtered resources,i.e . build is platform dependent! [INFO] --- maven-compiler-plugin:2.5.1:testCompile (- -first --- d is platform dependent! [INFO] Compiling 1 test- [INFO] --- maven-surefire-plugin:2.12.4:test (-test) @ hello-first --- surefire- ------------------------------------------------------- ------------------------------------------------------- Tests run: 1,Time elapsed: 0.03 Tests run: 1,Skipped: 0 [INFO] --- maven-jar-plugin:2.4:jar (-jar) @ hello-first --- [INFO] Building jar: D:\Development\workspace\maven_project\target\hello-first- NAPSHOT-0.0.1 [INFO] --- maven-install-plugin:2.4:install (-install) @ hello-first --- Downloading: http: s/3.0.5/plexus-utils-3.0.5 Downloaded: http: /3.0.5/plexus-utils-3.0.5.pom (3 KB at 5.2 KB/ Downloading: http: st/1.0/plexus-digest-1.0 Downloaded: http: t/1.0/plexus-digest-1.0.pom (2 KB at 1.8 KB/ Downloading: http: onents/1.1.7/plexus-components-1.1.7 Downloaded: http: nents/1.1.7/plexus-components-1.1.7.pom (5 KB at 10.2 KB/ Downloading: http: 8/plexus-1.0.8 Downloaded: http: /plexus-1.0.8.pom (8 KB at 10.1 KB/ Downloading: http: ainer-/1.0-alpha-8/plexus-container--1.0-alpha-8 Downloaded: http: iner-/1.0-alpha-8/plexus-container--1.0-alpha-8.pom (8 KB at 15.1 KB/ Downloading: http: s/3.0.5/plexus-utils-3.0.5 Downloading: http: st/1.0/plexus-digest-1.0 Downloaded: http: t/1.0/plexus-digest-1.0.jar (12 KB at 16.1 KB/ Downloaded: http: /3.0.5/plexus-utils-3.0.5.jar (226 KB at 115.9 KB/ [INFO] Installing D:\Development\workspace\maven_project\target\hello-first- SHOT-0.0.1 lo-first\SNAPSHOT-0.0.1\hello-first-SNAPSHOT-0.0.1 inistrator\.m2\repository\com\b510\maven\hello\hello-first\SNAPSHOT-0.0.1\hello- first-SNAPSHOT-0.0.1 [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] Total time: 10.014 [INFO] Finished at: 2014-07-06T10:57:39+08:00 [INFO] Final Memory: 5M/ [INFO] ------------------------------------------------------------------------ D:\Development\workspace\maven_project>

下面是运行后的效果

这样做有什么用呢?

既然加载到了本地仓库,那么就类似于本地仓库中的junit模块一样,我们在使用junit的时候,只是在pom.xml文件中配置一下,并不需要引入junit的相关jar包,同理。

我们要使用/maven_project/src/com/b510/maven/hello/Hello.java类的时候,也不用引入该类的jar文件,只需要在pom.xml文件中配置即可。

如:

com.b510.maven.hello hello-first SNAPSHOT-0.0.1

一个maven小程序,就差不多是这些,good luck!

========================================================

多读一些书,英语很重要。

More reading,and english is important.

I'm Hongten

hongten

========================================================

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐