Java-Maven(六):Eclipse中Maven插件的命令操作

之前几个章节学习了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 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 3   <modelVersion>4.0.0</modelVersion>
 4   <groupId>com.dx</groupId>
 5   <artifactId>maven-web-project01</artifactId>
 6   <packaging>war</packaging>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <name>maven-web-project01 Maven Webapp</name>
 9   <url>http://maven.apache.org</url>
10   <dependencies>
11     <dependency>
12       <groupId>junit</groupId>
13       <artifactId>junit</artifactId>
14       <version>3.8.1</version>
15       <scope>test</scope>
16     </dependency>
17   </dependencies>
18   <build>
19     <finalName>maven-web-project01</finalName>
20   </build>
21 </project>
复制代码

配置之后pom.xml内容如下:

复制代码
 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 3     <modelVersion>4.0.0</modelVersion>
 4     <groupId>com.dx</groupId>
 5     <artifactId>maven-web-project01</artifactId>
 6     <packaging>war</packaging>
 7     <version>0.0.1-SNAPSHOT</version>
 8     <name>maven-web-project01 Maven Webapp</name>
 9     <url>http://maven.apache.org</url>
10     <dependencies>
11         <dependency>
12             <groupId>junit</groupId>
13             <artifactId>junit</artifactId>
14             <version>3.8.1</version>
15             <scope>test</scope>
16         </dependency>
17     </dependencies>
18     <build>
19         <finalName>maven-web-project01</finalName>
20         <plugins>
21             <plugin>
22                 <groupId>org.apache.maven.plugins</groupId>
23                 <artifactId>maven-compiler-plugin</artifactId>
24                 <!-- 不设置采用最新的插件版本 ,也可以去http://maven.apache.org/components/plugins/maven-compiler-plugin/找自己需要的版本号 -->
25                 <version>3.1</version>
26                 <configuration>
27                     <!-- 源代码使用的开发版本 -->
28                     <source>1.8</source>
29                     <!-- 需要生成的目标class文件的编译版本 -->
30                     <target>1.8</target>
31                     <encoding>UTF-8</encoding>
32                 </configuration>
33             </plugin>
34         </plugins>
35     </build>
36 </project>
复制代码

配置之后,如果在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] ------------------------------------------------------------------------
复制代码
posted @ 2018-07-18 16:37  沧海一粟hr  阅读(904)  评论(0编辑  收藏  举报