Maven 的 HelloWorld

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <!--POM 版本类型-->
 6     <modelVersion>4.0.0</modelVersion>
 7     <!---->
 8     <groupId>org.zln.maven</groupId>
 9     <!--组中 id-->
10     <artifactId>hello-world</artifactId>
11     <!--版本-->
12     <version>1.0-SNAPSHOT</version>
13     <!--打包结果,默认 jar-->
14     <packaging>jar</packaging>
15     <!--更友好的项目名称-->
16     <name>Maven Hello World Project</name>
17 
18 
19     <properties>
20         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21     </properties>
22 
23     <!--设置依赖-->
24     <dependencies>
25         <dependency>
26             <groupId>junit</groupId>
27             <artifactId>junit</artifactId>
28             <version>4.12</version>
29         </dependency>
30     </dependencies>
31 
32     <build>
33         <plugins>
34             <!-- 资源文件拷贝插件 -->
35             <plugin>
36                 <groupId>org.apache.maven.plugins</groupId>
37                 <artifactId>maven-resources-plugin</artifactId>
38                 <version>2.7</version>
39                 <configuration>
40                     <encoding>UTF-8</encoding>
41                 </configuration>
42             </plugin>
43             <!-- java编译插件 -->
44             <plugin>
45                 <groupId>org.apache.maven.plugins</groupId>
46                 <artifactId>maven-compiler-plugin</artifactId>
47                 <version>3.2</version>
48                 <configuration>
49                     <source>1.8</source>
50                     <target>1.8</target>
51                     <encoding>UTF-8</encoding>
52                 </configuration>
53             </plugin>
54             <!--指定 main 方法-->
55             <plugin>
56                 <groupId>org.apache.maven.plugins</groupId>
57                 <artifactId>maven-jar-plugin</artifactId>
58                 <version>3.0.2</version>
59                 <configuration>
60                     <archive>
61                         <manifest>
62                             <addClasspath>true</addClasspath>
63                             <mainClass>org.zln.maven.helloworld.HelloWorld</mainClass>
64                         </manifest>
65                     </archive>
66                 </configuration>
67             </plugin>
68         </plugins>
69     </build>
70 
71 
72 </project>

测试:mvn clean test

打包:mvn clean package

原文地址:https://www.cnblogs.com/sherrykid/p/5904586.html