Maven项目核心:pom.xml (Project Object Model 项目对象模型)
以下为 实际操作实例:
1.首先创建一个名为hello-world(E:\MavenSrc\hello-world)的文件夹,在该文件夹下创建一个名为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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.juvenxu.mvnbook</groupId>
<artifactId>hello-world</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Hello World Project</name>
</project>
2.编写主代码
项目主代码会被打包到最终的构件中(如jar),而测试代码只在运行测试时用过,不会被打包。遵循Maven约定,Maven主代码位于
src/main/java目录,创建该目录,然后在该目录下创建文件E:\MavenSrc\hello-world\src\main\java\com\juvenxu\mvnbook\helloworld\HelloWorld.java
,其内容清单如下:
package com.juvenxu.mvnbook.helloworld;
public class HelloWorld {
public String sayHello(){
return "Hello Maven";
}
public static void main(String[] args){
System.out.print(new HelloWorld().sayHello());
}
}
代码编写完毕后,使用Maven进行编译,在项目根目录下(E:\MavenSrc\hello-world) 【pom.xml文件目录】
运行cmd命令:mvn clean compile
会得到如下输出:
E:\MavenSrc\hello-world>mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Hello World Project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-world ---
[INFO] Deleting E:\MavenSrc\hello-world\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-worl
d ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\main\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hello-world ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.693 s
[INFO] Finished at: 2015-05-18T22:27:04+08:00
[INFO] Final Memory: 13M/108M
[INFO] ------------------------------------------------------------------------
E:\MavenSrc\hello-world>
编译成功后,会在根目录下生成target目录!(编译后的class文件和编译插件)
注意:执行 mvn clean compile命令时,pom.xml文件不能处于打开编辑状态,不然会报构建失败!
3.编写测试代码
遵循Maven约定,Maven主代码位于
src/test/java目录,创建该目录,然后在该目录下创建文件E:\MavenSrc\hello-world\src\main\java\com\juvenxu\mvnbook\helloworld\HelloWorldTest.java
代码清单如下:
package com.juvenxu.mvnbook.helloworld;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class HelloWorldTest{
@Test
public void testSayHello(){
HelloWorld helloWorld = new HelloWorld();
String result = helloWorld.sayHello();
assertEquals("Hello Maven",result);
}
}
pom.xml文件中添加junit依赖:
代码如下:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.juvenxu.mvnbook</groupId>
<artifactId>hello-world</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Hello World Project</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
该根目录下运行: mvn clean test
运行结果如下:
E:\MavenSrc\hello-world>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Hello World Project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom (11 KB at 5.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire/2.12.4/surefire-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire/2.12.4/surefire-2.12.4.pom (14 KB at 36.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/junit/junit/4.7/junit-4.7.pom
Downloaded: https://repo.maven.apache.org/maven2/junit/junit/4.7/junit-4.7.pom (
2 KB at 3.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/junit/junit/4.7/junit-4.7.jar
Downloaded: https://repo.maven.apache.org/maven2/junit/junit/4.7/junit-4.7.jar (
227 KB at 180.8 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-world ---
[INFO] Deleting E:\MavenSrc\hello-world\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-worl
d ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\main\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hello-world ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
llo-world ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\test\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hello-w
orld ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-world ---
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-booter/2.12.4/surefire-booter-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-booter/2.12.4/surefire-booter-2.12.4.pom (3 KB at 7.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-api/2.12.4/surefire-api-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-api/2.12.4/surefire-api-2.12.4.pom (3 KB at 6.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/mave
n-surefire-common/2.12.4/maven-surefire-common-2.12.4.pom
Downloaded: https://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 14.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/
maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom (2 KB at 4.4 KB/sec
)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/
maven-plugin-tools/3.1/maven-plugin-tools-3.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-tools/3.1/maven-plugin-tools-3.1.pom (16 KB at 40.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mav
en-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom (2 KB at 4.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mav
en-reporting/2.0.9/maven-reporting-2.0.9.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting/2.0.9/maven-reporting-2.0.9.pom (2 KB at 4.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolcha
in/2.0.9/maven-toolchain-2.0.9.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchai
n/2.0.9/maven-toolchain-2.0.9.pom (4 KB at 9.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lan
g3/3.1/commons-lang3-3.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang
3/3.1/commons-lang3-3.1.pom (17 KB at 43.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/commons/commons-par
ent/22/commons-parent-22.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/commons/commons-pare
nt/22/commons-parent-22.pom (41 KB at 105.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.p
om
Downloaded: https://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.po
m (15 KB at 40.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
common-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom (4 KB at 9.7 KB
/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
shared-components/12/maven-shared-components-12.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-s
hared-components/12/maven-shared-components-12.pom (10 KB at 23.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/
13/maven-parent-13.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/1
3/maven-parent-13.pom (23 KB at 56.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-booter/2.12.4/surefire-booter-2.12.4.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/mave
n-surefire-common/2.12.4/maven-surefire-common-2.12.4.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-api/2.12.4/surefire-api-2.12.4.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lan
g3/3.1/commons-lang3-3.1.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
common-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-booter/2.12.4/surefire-booter-2.12.4.jar (34 KB at 82.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.8/plexus-utils-3.0.8.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar (31 KB at 32.6
KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mav
en-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.8/plexus-utils-3.0.8.jar (227 KB at 199.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolcha
in/2.0.9/maven-toolchain-2.0.9.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar (10 KB at 7.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/
maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-api/2.12.4/surefire-api-2.12.4.jar (115 KB at 78.1 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchai
n/2.0.9/maven-toolchain-2.0.9.jar (38 KB at 24.8 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar (14 KB at 8.2 KB/se
c)
Downloaded: https://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 134.0 KB/sec
)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang
3/3.1/commons-lang3-3.1.jar (309 KB at 146.6 KB/sec)
[INFO] Surefire report directory: E:\MavenSrc\hello-world\target\surefire-report
s
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-junit4/2.12.4/surefire-junit4-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-junit4/2.12.4/surefire-junit4-2.12.4.pom (3 KB at 5.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-providers/2.12.4/surefire-providers-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-providers/2.12.4/surefire-providers-2.12.4.pom (3 KB at 6.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/sure
fire-junit4/2.12.4/surefire-junit4-2.12.4.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
ire-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 KB at 94.1 KB/sec)
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.juvenxu.mvnbook.helloworld.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.079 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.206 s
[INFO] Finished at: 2015-05-18T22:57:59+08:00
[INFO] Final Memory: 18M/179M
[INFO] ------------------------------------------------------------------------
E:\MavenSrc\hello-world>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Hello World Project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-world ---
[INFO] Deleting E:\MavenSrc\hello-world\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-worl
d ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\main\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hello-world ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
llo-world ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\test\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hello-w
orld ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-world ---
[INFO] Surefire report directory: E:\MavenSrc\hello-world\target\surefire-report
s
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.juvenxu.mvnbook.helloworld.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.094 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.766 s
[INFO] Finished at: 2015-05-18T23:00:01+08:00
[INFO] Final Memory: 16M/181M
[INFO] ------------------------------------------------------------------------
E:\MavenSrc\hello-world>
注意:观察执行 mvn clean test的时候,先是删除了target文件夹然后又生成的,即执行该命令的时候,也进行了mvn clean complie相同的操作,先编译,后测试!
4.打包和运行
根目录下运行mvn clean package
结果输出如下:
E:\MavenSrc\hello-world>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Hello World Project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-jar-plugin/2.4/maven-jar-plugin-2.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
jar-plugin/2.4/maven-jar-plugin-2.4.pom (6 KB at 2.7 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-world ---
[INFO] Deleting E:\MavenSrc\hello-world\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-worl
d ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\main\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hello-world ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
llo-world ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenSrc\hello-world\src\test\reso
urces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hello-w
orld ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 1 source file to E:\MavenSrc\hello-world\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-world ---
[INFO] Surefire report directory: E:\MavenSrc\hello-world\target\surefire-report
s
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.juvenxu.mvnbook.helloworld.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.091 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hello-world ---
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archive
r/2.5/maven-archiver-2.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver
/2.5/maven-archiver-2.5.pom (5 KB at 11.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arc
hiver/2.1/plexus-archiver-2.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
iver/2.1/plexus-archiver-2.1.pom (3 KB at 7.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/
2.0.2/plexus-io-2.0.2.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
.0.2/plexus-io-2.0.2.pom (2 KB at 4.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-com
ponents/1.1.19/plexus-components-1.1.19.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
onents/1.1.19/plexus-components-1.1.19.pom (3 KB at 7.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.0
.1/plexus-3.0.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.0.
1/plexus-3.0.1.pom (19 KB at 31.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-int
erpolation/1.15/plexus-interpolation-1.15.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.15/plexus-interpolation-1.15.pom (1018 B at 2.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/
commons-lang-2.1.pom
Downloaded: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/c
ommons-lang-2.1.pom (10 KB at 26.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archive
r/2.5/maven-archiver-2.5.jar
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-int
erpolation/1.15/plexus-interpolation-1.15.jar
Downloading: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-al
pha-2/classworlds-1.1-alpha-2.jar
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/
2.0.2/plexus-io-2.0.2.jar
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arc
hiver/2.1/plexus-archiver-2.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver
/2.5/maven-archiver-2.5.jar (22 KB at 38.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/
commons-lang-2.1.jar
Downloaded: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alp
ha-2/classworlds-1.1-alpha-2.jar (37 KB at 32.4 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
rpolation/1.15/plexus-interpolation-1.15.jar (60 KB at 51.2 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
.0.2/plexus-io-2.0.2.jar (57 KB at 49.3 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
iver/2.1/plexus-archiver-2.1.jar (181 KB at 112.6 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/c
ommons-lang-2.1.jar (203 KB at 125.8 KB/sec)
[INFO] Building jar: E:\MavenSrc\hello-world\target\hello-world-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.705 s
[INFO] Finished at: 2015-05-18T23:14:37+08:00
[INFO] Final Memory: 19M/179M
[INFO] ------------------------------------------------------------------------
E:\MavenSrc\hello-world>
类似的,Maven会在打包前进行编译,测试等操作。
这里得到了项目的输出,如果需要的话,就可以复制这个jar文件到其他项目的Classpath中从而使用HelloWorld类。
但是要让其他Maven项目直接引用这个jar的话,还需要一个安装的步骤:执行mvn clean install
运行结果如下(这里只贴install部分信息):
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-dige
st/1.0/plexus-digest-1.0.jar (12 KB at 0.3 KB/sec)
[INFO] Installing E:\MavenSrc\hello-world\target\hello-world-1.0-SNAPSHOT.jar to
C:\Users\admin\.m2\repository\com\juvenxu\mvnbook\hello-world\1.0-SNAPSHOT\hell
o-world-1.0-SNAPSHOT.jar
[INFO] Installing E:\MavenSrc\hello-world\pom.xml to C:\Users\admin\.m2\reposito
ry\com\juvenxu\mvnbook\hello-world\1.0-SNAPSHOT\hello-world-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46.891 s
[INFO] Finished at: 2015-05-18T23:24:22+08:00
[INFO] Final Memory: 20M/177M
[INFO] ------------------------------------------------------------------------
E:\MavenSrc\hello-world>
根据信息知道该任务将项目输出的jar安装到了Maven本地仓库中。
以上为手动创建Maven项目骨架实例,以便学习过程中能更详细的了解Maven创建项目的每一步的用意,以供参考!!!