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

关于maven的安装 : Install Maven in your computer

先看看目录结构:

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

即:

pom.xml文件要和src目录在同一级

在src目录下面,分别为main目录和test目录

在main目录下面存放项目中的模块类,如这里的com.b510.maven.hello.Hello.java

在test目录下面存放项目模块的测试类,如这里的com.b510.maven.hello.test.HelloTest.java

NOTE:

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

接下来才是关键:

/maven_project/pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.b510.maven.hello</groupId>
<artifactId>hello-first</artifactId>
<version>SNAPSHOT-0.0.1</version> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

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类

/maven_project/src/com/b510/maven/hello/Hello.java

 /**
*
*/
package com.b510.maven.hello; /**
* @author Hongten
* @created 2014-7-5
*/
public class Hello { public static void main(String[] args) {
System.out.println("This is a test message!");
String str = new Hello().sayHello("Hongten", 20);
System.out.println(str);
} public String sayHello(String name, int age){
return "I'm " + name + ", I'm " + age + ", Hello";
}
}

/maven_project/src/com/b510/maven/hello/test/HelloTest.java

 /**
*
*/
package com.b510.maven.hello.test; import static org.junit.Assert.*; import org.junit.Test; import com.b510.maven.hello.Hello; /**
* @author Hongten
* @created 2014-7-5
*/
public class HelloTest { @Test
public void testSayHello() {
Hello hello = new Hello();
assertEquals(hello.sayHello("Hongten", 20), "I'm Hongten, I'm 20, Hello");
} }

两个类都是很简单的类。

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

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

1.运行命令:mvn compile

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

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

 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-p
arameter-documenter/2.0.6/maven-plugin-parameter-documenter-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-pa
rameter-documenter/2.0.6/maven-plugin-parameter-documenter-2.0.6.pom (2 KB at 3.
8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/2.0.6/maven-reporting-api-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting-api/2.0.6/maven-reporting-api-2.0.6.pom (2 KB at 3.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting/2.0.6/maven-reporting-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting/2.0.6/maven-reporting-2.0.6.pom (2 KB at 3.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-si
nk-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-sin
k-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.pom (424 B at 0.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia/1.
0-alpha-7/doxia-1.0-alpha-7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia/1.0
-alpha-7/doxia-1.0-alpha-7.pom (4 KB at 8.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-di
agnostics/2.0.6/maven-error-diagnostics-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-dia
gnostics/2.0.6/maven-error-diagnostics-2.0.6.pom (2 KB at 3.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/com
mons-cli-1.0.pom
Downloaded: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/comm
ons-cli-1.0.pom (3 KB at 4.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-d
escriptor/2.0.6/maven-plugin-descriptor-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-de
scriptor/2.0.6/maven-plugin-descriptor-2.0.6.pom (2 KB at 4.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
ractivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
activity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.pom (7 KB at 13.6
KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/
2.0.6/maven-monitor-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/2
.0.6/maven-monitor-2.0.6.pom (2 KB at 2.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/classworlds/classworlds/1.1/cla
ssworlds-1.1.pom
Downloaded: http://repo.maven.apache.org/maven2/classworlds/classworlds/1.1/clas
sworlds-1.1.pom (4 KB at 6.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/2.0.5/plexus-utils-2.0.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/2.0.5/plexus-utils-2.0.5.pom (4 KB at 6.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.
6/plexus-2.0.6.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.6
/plexus-2.0.6.pom (17 KB at 21.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-f
iltering/1.1/maven-filtering-1.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-fi
ltering/1.1/maven-filtering-1.1.pom (6 KB at 11.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-s
hared-components/17/maven-shared-components-17.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-sh
ared-components/17/maven-shared-components-17.pom (9 KB at 15.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/1.5.15/plexus-utils-1.5.15.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/1.5.15/plexus-utils-1.5.15.pom (7 KB at 8.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.
2/plexus-2.0.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.2
/plexus-2.0.2.pom (12 KB at 13.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.12/plexus-interpolation-1.12.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
polation/1.12/plexus-interpolation-1.12.pom (889 B at 1.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
onents/1.1.14/plexus-components-1.1.14.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
nents/1.1.14/plexus-components-1.1.14.pom (6 KB at 10.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-buil
d-api/0.0.4/plexus-build-api-0.0.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-build
-api/0.0.4/plexus-build-api-0.0.4.pom (3 KB at 4.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent
/10/spice-parent-10.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/
10/spice-parent-10.pom (3 KB at 5.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent
/3/forge-parent-3.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/
3/forge-parent-3.pom (5 KB at 8.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/1.5.8/plexus-utils-1.5.8.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/1.5.8/plexus-utils-1.5.8.pom (8 KB at 13.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.13/plexus-interpolation-1.13.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
polation/1.13/plexus-interpolation-1.13.pom (890 B at 1.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
onents/1.1.15/plexus-components-1.1.15.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
nents/1.1.15/plexus-components-1.1.15.pom (3 KB at 4.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.
3/plexus-2.0.3.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.3
/plexus-2.0.3.pom (16 KB at 17.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-si
nk-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
ractivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
Downloading: http://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.j
ar
Downloading: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/com
mons-cli-1.0.jar
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-sin
k-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar (6 KB at 10.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/2.0.5/plexus-utils-2.0.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar (10 KB at 11.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-f
iltering/1.1/maven-filtering-1.1.jar
Downloaded: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/comm
ons-cli-1.0.jar (30 KB at 27.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-buil
d-api/0.0.4/plexus-build-api-0.0.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
activity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar (14 KB at 10.4
KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.13/plexus-interpolation-1.13.jar
Downloaded: http://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.ja
r (119 KB at 73.9 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-build
-api/0.0.4/plexus-build-api-0.0.4.jar (7 KB at 11.8 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-fi
ltering/1.1/maven-filtering-1.1.jar (43 KB at 38.9 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/2.0.5/plexus-utils-2.0.5.jar (218 KB at 91.8 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
polation/1.13/plexus-interpolation-1.13.jar (60 KB at 28.9 KB/sec)
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
--
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-a
pi/2.0.9/maven-plugin-api-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-ap
i/2.0.9/maven-plugin-api-2.0.9.pom (2 KB at 3.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven/2.0.9/ma
ven-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven/2.0.9/mav
en-2.0.9.pom (19 KB at 26.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/8
/maven-parent-8.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/8/
maven-parent-8.pom (24 KB at 34.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/4/apache-4.po
m
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/4/apache-4.pom
(5 KB at 9.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
/2.0.9/maven-artifact-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact/
2.0.9/maven-artifact-2.0.9.pom (2 KB at 3.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/1.5.1/plexus-utils-1.5.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/1.5.1/plexus-utils-1.5.1.pom (3 KB at 4.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/2.0
.9/maven-core-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/2.0.
9/maven-core-2.0.9.pom (8 KB at 11.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings
/2.0.9/maven-settings-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/
2.0.9/maven-settings-2.0.9.pom (3 KB at 4.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.
0.9/maven-model-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.0
.9/maven-model-2.0.9.pom (4 KB at 6.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-p
arameter-documenter/2.0.9/maven-plugin-parameter-documenter-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-pa
rameter-documenter/2.0.9/maven-plugin-parameter-documenter-2.0.9.pom (2 KB at 4.
2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/
2.0.9/maven-profile-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/2
.0.9/maven-profile-2.0.9.pom (3 KB at 4.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-reposito
ry-metadata/2.0.9/maven-repository-metadata-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-repositor
y-metadata/2.0.9/maven-repository-metadata-2.0.9.pom (2 KB at 3.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-di
agnostics/2.0.9/maven-error-diagnostics-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-dia
gnostics/2.0.9/maven-error-diagnostics-2.0.9.pom (2 KB at 3.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-project/
2.0.9/maven-project-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-project/2
.0.9/maven-project-2.0.9.pom (3 KB at 5.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
-manager/2.0.9/maven-artifact-manager-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact-
manager/2.0.9/maven-artifact-manager-2.0.9.pom (3 KB at 5.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-r
egistry/2.0.9/maven-plugin-registry-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-re
gistry/2.0.9/maven-plugin-registry-2.0.9.pom (2 KB at 3.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-d
escriptor/2.0.9/maven-plugin-descriptor-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-de
scriptor/2.0.9/maven-plugin-descriptor-2.0.9.pom (3 KB at 3.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/
2.0.9/maven-monitor-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/2
.0.9/maven-monitor-2.0.9.pom (2 KB at 2.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchai
n/1.0/maven-toolchain-1.0.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain
/1.0/maven-toolchain-1.0.pom (4 KB at 6.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0/plexus-utils-3.0.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/3.0/plexus-utils-3.0.pom (4 KB at 7.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent
/16/spice-parent-16.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/
16/spice-parent-16.pom (9 KB at 16.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent
/5/forge-parent-5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/
5/forge-parent-5.pom (9 KB at 15.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler-api/1.9.1/plexus-compiler-api-1.9.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler-api/1.9.1/plexus-compiler-api-1.9.1.pom (867 B at 1.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler/1.9.1/plexus-compiler-1.9.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler/1.9.1/plexus-compiler-1.9.1.pom (4 KB at 7.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
onents/1.1.20/plexus-components-1.1.20.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
nents/1.1.20/plexus-components-1.1.20.pom (3 KB at 6.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/
plexus-3.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/p
lexus-3.1.pom (19 KB at 26.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent
/17/spice-parent-17.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/
17/spice-parent-17.pom (7 KB at 13.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent
/10/forge-parent-10.pom
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/
10/forge-parent-10.pom (14 KB at 19.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom (692 B at 1.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom (688 B at 1.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
ilers/1.9.1/plexus-compilers-1.9.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
lers/1.9.1/plexus-compilers-1.9.1.pom (2 KB at 2.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0/plexus-utils-3.0.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
iler-api/1.9.1/plexus-compiler-api-1.9.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar (5 KB at 6.3 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar (14 KB at 15.0 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
ler-api/1.9.1/plexus-compiler-api-1.9.1.jar (21 KB at 22.5 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/3.0/plexus-utils-3.0.jar (221 KB at 89.4 KB/sec)
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:06 min
[INFO] Finished at: 2014-07-06T10:39:32+08:00
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------
D:\Development\workspace\maven_project>

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

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

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

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

 Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\Administrator>D: D:\>cd D:\Development\workspace\maven_project D:\Development\workspace\maven_project>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hello-first SNAPSHOT-0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
t ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
--
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.699 s
[INFO] Finished at: 2014-07-06T10:45:33+08:00
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------
D:\Development\workspace\maven_project>

2.执行命令:mvn test

 D:\Development\workspace\maven_project>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hello-first SNAPSHOT-0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-s
urefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom (11 KB at 12.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire/2.12.4/surefire-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re/2.12.4/surefire-2.12.4.pom (14 KB at 29.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-s
urefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar (30 KB at 33.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/junit/junit/4.10/junit-4.10.jar Downloading: http://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.1/
hamcrest-core-1.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.1/h
amcrest-core-1.1.jar (75 KB at 48.7 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/junit/junit/4.10/junit-4.10.jar
(248 KB at 114.4 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
t ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
--
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
llo-first ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hello
-first ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-first ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-booter/2.12.4/surefire-booter-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-booter/2.12.4/surefire-booter-2.12.4.pom (3 KB at 6.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-api/2.12.4/surefire-api-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-api/2.12.4/surefire-api-2.12.4.pom (3 KB at 5.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven
-surefire-common/2.12.4/maven-surefire-common-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-
surefire-common/2.12.4/maven-surefire-common-2.12.4.pom (6 KB at 11.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
ven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom (2 KB at 3.4 KB/sec) Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-tools/3.1/maven-plugin-tools-3.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
ven-plugin-tools/3.1/maven-plugin-tools-3.1.pom (16 KB at 23.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.8/plexus-utils-3.0.8.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/3.0.8/plexus-utils-3.0.8.pom (4 KB at 6.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.2/
plexus-3.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.2/p
lexus-3.2.pom (19 KB at 25.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom (2 KB at 3.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting/2.0.9/maven-reporting-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting/2.0.9/maven-reporting-2.0.9.pom (2 KB at 3.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchai
n/2.0.9/maven-toolchain-2.0.9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain
/2.0.9/maven-toolchain-2.0.9.pom (4 KB at 7.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang
3/3.1/commons-lang3-3.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3
/3.1/commons-lang3-3.1.pom (17 KB at 17.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-pare
nt/22/commons-parent-22.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-paren
t/22/commons-parent-22.pom (41 KB at 31.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.po
m
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom
(15 KB at 29.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-co
mmon-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom (4 KB at 7.8 KB/
sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-s
hared-components/12/maven-shared-components-12.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-sh
ared-components/12/maven-shared-components-12.pom (10 KB at 13.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/1
3/maven-parent-13.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/13
/maven-parent-13.pom (23 KB at 32.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/6/apache-6.po
m
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/6/apache-6.pom
(13 KB at 25.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-cont
ainer-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-conta
iner-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.pom (2 KB at 2.6 K
B/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-booter/2.12.4/surefire-booter-2.12.4.jar
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven
-surefire-common/2.12.4/maven-surefire-common-2.12.4.jar
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang
3/3.1/commons-lang3-3.1.jar
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-api/2.12.4/surefire-api-2.12.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-co
mmon-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar (31 KB at 34.4 K
B/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.8/plexus-utils-3.0.8.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-booter/2.12.4/surefire-booter-2.12.4.jar (34 KB at 31.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-api/2.12.4/surefire-api-2.12.4.jar (115 KB at 75.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar (10 KB at 18.7 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
ven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar (14 KB at 28.4 KB/se
c)
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3
/3.1/commons-lang3-3.1.jar (309 KB at 145.2 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-
surefire-common/2.12.4/maven-surefire-common-2.12.4.jar (257 KB at 117.9 KB/sec) Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/3.0.8/plexus-utils-3.0.8.jar (227 KB at 116.0 KB/sec)
[INFO] Surefire report directory: D:\Development\workspace\maven_project\target\
surefire-reports
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-junit4/2.12.4/surefire-junit4-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-junit4/2.12.4/surefire-junit4-2.12.4.pom (3 KB at 5.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-providers/2.12.4/surefire-providers-2.12.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-providers/2.12.4/surefire-providers-2.12.4.pom (3 KB at 4.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-junit4/2.12.4/surefire-junit4-2.12.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
re-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 KB at 33.0 KB/sec) -------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.b510.maven.hello.test.HelloTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.038 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.319 s
[INFO] Finished at: 2014-07-06T10:46:53+08:00
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
D:\Development\workspace\maven_project>

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

下面进行打包操作

3.执行命令:mvn package

 Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\Administrator>D: D:\>cd D:\Development\workspace\maven_project D:\Development\workspace\maven_project>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hello-first SNAPSHOT-0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
jar-plugin/2.4/maven-jar-plugin-2.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-j
ar-plugin/2.4/maven-jar-plugin-2.4.pom (6 KB at 3.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
jar-plugin/2.4/maven-jar-plugin-2.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-j
ar-plugin/2.4/maven-jar-plugin-2.4.jar (34 KB at 36.3 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
t ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
--
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
llo-first ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hello
-first ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-first ---
[INFO] Surefire report directory: D:\Development\workspace\maven_project\target\
surefire-reports -------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.b510.maven.hello.test.HelloTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hello-first ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver
/2.5/maven-archiver-2.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/
2.5/maven-archiver-2.5.pom (5 KB at 9.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
iver/2.1/plexus-archiver-2.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archi
ver/2.1/plexus-archiver-2.1.pom (3 KB at 5.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
.0.2/plexus-io-2.0.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.
0.2/plexus-io-2.0.2.pom (2 KB at 3.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
onents/1.1.19/plexus-components-1.1.19.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
nents/1.1.19/plexus-components-1.1.19.pom (3 KB at 5.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.0.
1/plexus-3.0.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.0.1
/plexus-3.0.1.pom (19 KB at 34.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.15/plexus-interpolation-1.15.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
polation/1.15/plexus-interpolation-1.15.pom (1018 B at 2.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/c
ommons-lang-2.1.pom
Downloaded: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/co
mmons-lang-2.1.pom (10 KB at 20.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver
/2.5/maven-archiver-2.5.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
.0.2/plexus-io-2.0.2.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.15/plexus-interpolation-1.15.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
iver/2.1/plexus-archiver-2.1.jar
Downloading: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/c
ommons-lang-2.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/
2.5/maven-archiver-2.5.jar (22 KB at 39.7 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.
0.2/plexus-io-2.0.2.jar (57 KB at 54.0 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
polation/1.15/plexus-interpolation-1.15.jar (60 KB at 50.3 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/co
mmons-lang-2.1.jar (203 KB at 117.4 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archi
ver/2.1/plexus-archiver-2.1.jar (181 KB at 104.1 KB/sec)
[INFO] Building jar: D:\Development\workspace\maven_project\target\hello-first-S
NAPSHOT-0.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.989 s
[INFO] Finished at: 2014-07-06T10:49:01+08:00
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
D:\Development\workspace\maven_project>

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

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

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

4.执行命令:mvn clean

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

 D:\Development\workspace\maven_project>mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hello-first SNAPSHOT-0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-c
lean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 5.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
clean-plugin/2.5/maven-clean-plugin-2.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-c
lean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 37.2 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-first ---
[INFO] Deleting D:\Development\workspace\maven_project\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.066 s
[INFO] Finished at: 2014-07-06T10:55:13+08:00
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------
D:\Development\workspace\maven_project>

5.命令:mvn install

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

 Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\Administrator>D: D:\>cd D:\Development\workspace\maven_project D:\Development\workspace\maven_project>mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hello-first SNAPSHOT-0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
install-plugin/2.4/maven-install-plugin-2.4.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-i
nstall-plugin/2.4/maven-install-plugin-2.4.pom (7 KB at 3.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
install-plugin/2.4/maven-install-plugin-2.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-i
nstall-plugin/2.4/maven-install-plugin-2.4.jar (27 KB at 37.0 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
t ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
--
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to D:\Development\workspace\maven_project\target\
classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
llo-first ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Development\workspace\maven_projec
t\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hello
-first ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to D:\Development\workspace\maven_project\target\
test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-first ---
[INFO] Surefire report directory: D:\Development\workspace\maven_project\target\
surefire-reports -------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.b510.maven.hello.test.HelloTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hello-first ---
[INFO] Building jar: D:\Development\workspace\maven_project\target\hello-first-S
NAPSHOT-0.0.1.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ hello-first ---
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.5/plexus-utils-3.0.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/3.0.5/plexus-utils-3.0.5.pom (3 KB at 5.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-dige
st/1.0/plexus-digest-1.0.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-diges
t/1.0/plexus-digest-1.0.pom (2 KB at 1.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
onents/1.1.7/plexus-components-1.1.7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
nents/1.1.7/plexus-components-1.1.7.pom (5 KB at 10.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.
8/plexus-1.0.8.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8
/plexus-1.0.8.pom (8 KB at 10.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-cont
ainer-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-conta
iner-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (8 KB at 15.1
KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.5/plexus-utils-3.0.5.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-dige
st/1.0/plexus-digest-1.0.jar
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-diges
t/1.0/plexus-digest-1.0.jar (12 KB at 16.1 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
/3.0.5/plexus-utils-3.0.5.jar (226 KB at 115.9 KB/sec)
[INFO] Installing D:\Development\workspace\maven_project\target\hello-first-SNAP
SHOT-0.0.1.jar to C:\Users\Administrator\.m2\repository\com\b510\maven\hello\hel
lo-first\SNAPSHOT-0.0.1\hello-first-SNAPSHOT-0.0.1.jar
[INFO] Installing D:\Development\workspace\maven_project\pom.xml to C:\Users\Adm
inistrator\.m2\repository\com\b510\maven\hello\hello-first\SNAPSHOT-0.0.1\hello-
first-SNAPSHOT-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.014 s
[INFO] Finished at: 2014-07-06T10:57:39+08:00
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
D:\Development\workspace\maven_project>

下面是运行后的效果:

这样做有什么用呢?

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

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

如:

 <dependencies>
<dependency>
<groupId>com.b510.maven.hello</groupId>
<artifactId>hello-first</artifactId>
<version>SNAPSHOT-0.0.1</version>
</dependency>
</dependencies>

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

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

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

More reading,and english is important.

I'm Hongten

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

Maven的第一个小程序的更多相关文章

  1. TODO:即将开发的第一个小程序

    TODO:即将开发的第一个小程序 微信小程序是一种全新的连接用户与服务的方式,它可以在微信内被便捷地获取和传播,同时具有出色的使用体验.个人理解小程序是寄宿在微信平台上的一个前端框架,具有跨平台功能, ...

  2. 微信小程序-----安装,编写第一个小程序和运行到手机端

    第一步: 微信公众平台注册账号,并选择小程序,网址:mp.weixin.qq.com 填写相关信息,如:主体类型(个人或者企业) AppID  在开发中都是用的到的,服务器域名在网络请求也是用的到的. ...

  3. Struts2学习笔记——Struts2搭建和第一个小程序

    1.新建web项目 2.配置Struts2核心过滤器 (1)打开web.xml文件,做以下配置: <?xml version="1.0" encoding="UTF ...

  4. 自学Android的第一个小程序(小布局、button点击事件、toast弹出)

    因为上班,学习时间有限,昨晚才根据教程写了一个小程序,今天忙里偷闲写一下如何实现的,来加深一下印象. 首先创建一个Android项目, 通过activity_xxx.xml布局文件来添加组件来达到自己 ...

  5. 动手搭建第一个小程序音视频Demo

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者:小程序音视频产品经理 腾讯云提供了全套技术文档和源码来帮助您快速构建一个音视频小程序,但是再好的源码和文档也有学习成本,为了尽快的能调试起 ...

  6. 微信小程序——创建自己的第一个小程序【一】

    注册 微信小程序注册 https://mp.weixin.qq.com/wxopen/waregister?action=step1   填写账号信息  作为登录帐号,请填写未被微信公众平台注册,未被 ...

  7. python3速查参考- python基础 1 -> python版本选择+第一个小程序

    题外话: Python版本:最新的3.6 安装注意点:勾选添加路径后自定义安装到硬盘的一级目录,例如本人的安装路径: F:\Python 原因:可以自动添加python环境变量,自动关联.py文件,其 ...

  8. Python 的第一个小程序

    F盘   新建文本文档 hello.txt 内容为: print("hello world! hello 2018!"); 打开CMD cd c:\                 ...

  9. [开源]入坑Qt,我的第一个小程序:MD5计算器

    版权声明 --------- 本文仅在知乎与博客园发布.开发者为szx0427 MFC和Win32搞了好几年了,也算是懂了个皮毛,但是一直觉得用这两者开发软件都很麻烦,需要将大量的代码花费在UI等地方 ...

随机推荐

  1. 使用getopt函数对windows命令行程序进行参数解析

    getopt()是libc的标准函数,很多语言中都能找到它的移植版本. // -b -p "c:\input" -o "e:\test\output" bool ...

  2. WCF消息拦截,利用消息拦截做身份验证服务

    本文参考  http://blog.csdn.net/tcjiaan/article/details/8274493  博客而写 添加对信息处理的类 /// <summary> /// 消 ...

  3. hdu 5289 rmp+二分+枚举后界 or单调队列 ****

    好题~~ 给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数,枚举后界~~ 又是一种没见过的方法,太弱了/(ㄒoㄒ)/~~ #include <cstdio ...

  4. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

  5. 跟着鸟哥学Linux系列笔记3-第11章BASH学习

    跟着鸟哥学Linux系列笔记0-扫盲之概念 跟着鸟哥学Linux系列笔记0-如何解决问题 跟着鸟哥学Linux系列笔记1 跟着鸟哥学Linux系列笔记2-第10章VIM学习 认识与学习bash 1. ...

  6. 国内大学毕业论文 LaTeX 模板集合

    西北工业大学学位论文LaTeX模板 http://code.google.com/p/nwputhesis/ 西北工业大学硕博士论文LaTeX模版 http://code.google.com/p/n ...

  7. 让sql语句不排序,按照in语句的顺序返回结果

    SELECT * FROM EVENT WHERE eventId IN(443,419,431,440,420,414,509)  ORDER BY INSTR(',443,419,431,440, ...

  8. 面向服务的架构SOA

    SOA简介 SCA实现SOA的最佳方式 Apache开源框架Tuscany实现SCA架构 SOA简单描述: SOA(Service-Oriented Architecture)面向服务的体系架构.为了 ...

  9. 介绍linux下vi命令的使用

    功能最强大的编辑器之一——vivi是所有UNIX系统都会提供的屏幕编辑器,它提供了一个视窗设备,通过它可以编辑文件.当然,对UNIX系统略有所知的人,或多或少都觉得vi超级难用,但vi是最基本的编辑器 ...

  10. SoapUI之webservice接口测试(一)

    1.新建soap project 添加后出现接口内容 2.为了方便后续的测试,以防某些参数删除错了,这边需要新建测试集 3.点开新建的测试集可以发现,里面的内容跟原始测试集内容是一样的 然后就可以在这 ...