之前几个章节学习了maven的概念,及maven插件安装后如何创建工程,那么maven工程中是如何使用maven命令呢?本章节将会学习这个话题。
在pom.xml中配置maven命令插件
如果向在maven工程中使用maven命令,就必须在pom.xml文件中配置maven命令插件。接下来基于上一章文章(《Java-Maven(五):Eclipse&Maven下创建java工程&web工程》)中创建的java web maven工程之上,进行pom.xml下配置安装maven命令插件。
配置之前pom.xml内容如下:
1
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 4.0.0
4 com.dx
5 maven-web-project01
6 war
7 0.0.1-SNAPSHOT
8 maven-web-project01 Maven Webapp
9 http://maven.apache.org
10
11
12 junit
13 junit
14 3.8.1
15 test
16
17
18
19 maven-web-project01
20
21
配置之后pom.xml内容如下:
1
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 4.0.0
4 com.dx
5 maven-web-project01
6 war
7 0.0.1-SNAPSHOT
8 maven-web-project01 Maven Webapp
9 http://maven.apache.org
10
11
12 junit
13 junit
14 3.8.1
15 test
16
17
18
19 maven-web-project01
20
21
22 org.apache.maven.plugins
23 maven-compiler-plugin
24
25 3.1
26
27
28 1.8
29
30 1.8
31 UTF-8
32
33
34
35
36
配置之后,如果在pom.xml上右键-》Run As下包含如下截图内容,就说明安装成功。
在maven工程中执行maven命令:
我们可以基于上边的安装后maven命令插件后,测试体验下Maven install的作用,点击后控制台会打印信息:
1 [INFO] Scanning for projects...
2 [INFO]
3 [INFO] ------------------------------------------------------------------------
4 [INFO] Building maven-web-project01 Maven Webapp 0.0.1-SNAPSHOT
5 [INFO] ------------------------------------------------------------------------
6 [INFO]
7 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-web-project01 ---
8 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
9 [INFO] Copying 0 resource
10 [INFO]
11 [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-web-project01 ---
12 [INFO] Changes detected - recompiling the module!
13 [INFO] Compiling 1 source file to D:\workspace4\maven-web-project01\target\classes
14 [INFO]
15 [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-web-project01 ---
16 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
17 [INFO] skip non existing resourceDirectory D:\workspace4\maven-web-project01\src\test\resources
18 [INFO]
19 [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-web-project01 ---
20 [INFO] Nothing to compile - all classes are up to date
21 [INFO]
22 [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-web-project01 ---
23 [INFO]
24 [INFO] --- maven-war-plugin:2.2:war (default-war) @ maven-web-project01 ---
25 [INFO] Packaging webapp
26 [INFO] Assembling webapp [maven-web-project01] in [D:\workspace4\maven-web-project01\target\maven-web-project01]
27 [INFO] Processing war project
28 [INFO] Copying webapp resources [D:\workspace4\maven-web-project01\src\main\webapp]
29 [INFO] Webapp assembled in [37 msecs]
30 [INFO] Building war: D:\workspace4\maven-web-project01\target\maven-web-project01.war
31 [INFO] WEB-INF\web.xml already added, skipping
32 [INFO]
33 [INFO] --- maven-install-plugin:2.4:install (default-install) @ maven-web-project01 ---
34 [INFO] Installing D:\workspace4\maven-web-project01\target\maven-web-project01.war to C:\Users\Administrator\.m2\repository\com\dx\maven-web-project01\0.0.1-SNAPSHOT\maven-web-project01-0.0.1-SNAPSHOT.war
35 [INFO] Installing D:\workspace4\maven-web-project01\pom.xml to C:\Users\Administrator\.m2\repository\com\dx\maven-web-project01\0.0.1-SNAPSHOT\maven-web-project01-0.0.1-SNAPSHOT.pom
36 [INFO] ------------------------------------------------------------------------
37 [INFO] BUILD SUCCESS
38 [INFO] ------------------------------------------------------------------------
39 [INFO] Total time: 3.263 s
40 [INFO] Finished at: 2017-06-28T02:16:57+08:00
41 [INFO] Final Memory: 18M/201M
42 [INFO] ------------------------------------------------------------------------