Maven部分配置项解释

首先来看我当前的pom.xml文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?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>你的id</groupId>
<artifactId>你的id</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<build.target.pathname>你的路径名</build.target.pathname>
<build.target.dir>${project.basedir}/${build.target.pathname}</build.target.dir>
</properties>

<build>
<plugins>
<!--删除生成的目标目录-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<!--在这里指定哪些文件夹也需要删除 -->
<fileset>
<directory>${build.target.pathname}</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<!--将依赖放入lib文件夹-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 在这里将依赖的jar包(你程序的依赖),copy进哪个文件夹-->
<outputDirectory>${build.target.dir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!--排除打入jar包的文件路径-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- 在这里是指将编译好的jar包(你自己的程序),copy进哪个文件夹-->
<outputDirectory>
${build.target.dir}/lib
</outputDirectory>
<!--这个选项是在文件中生成classpath,这样只通过"java -cp jarname mainclass"执行自己的jar包就可以了-->
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>
</manifest>
</archive>
<excludes>
<!--在这里表示,会排除static路径下的所有文件,不会打入jar包中,这个路径需要是classes目录的相对路径
https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html
实际就是resources下的路径,比如我这里static文件夹就位于resources下
-->
<exclude>static/**</exclude>
</excludes>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-assembly-plugin</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- <configuration>-->
<!-- <descriptorRefs>-->
<!-- <descriptorRef>jar-with-dependencies</descriptorRef>-->
<!-- </descriptorRefs>-->
<!-- <outputDirectory>${build.target.dir}/lib</outputDirectory>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>make-assembly</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>single</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!--用来指定将哪些文件复制到哪里去-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!--复制的目标地址,这个变量是我自定义的-->
<outputDirectory>${build.target.dir}</outputDirectory>
<resources>
<!--资源地址-->
<resource>
<directory>
${project.basedir}/src/main/resources/static/
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.63.Final</version>
</dependency>
</dependencies>
</project>

pom文件的整体说明如上,接下来具体介绍一下pom文件中的不同内容。

Maven内置变量

1
2
3
4
5
6
7
8
9
${project.build.sourceDirectory}:项目的主源码目录,默认为src/main/java/.   
${project.build.testSourceDirectory}:项目的测试源码目录,默认为/src/test/java/.
${project.build.directory}:项目构建输出目录,默认为target/.
${project.build.outputDirectory}:项目主代码编译输出目录,默认为target/classes/.
${project.build.testOutputDirectory}:项目测试代码编译输出目录,默认为target/testclasses/.
${project.groupId}:项目的groupId.
${project.artifactId}:项目的artifactId.
${project.version}:项目的version,等同于${version}
${project.build.finalName}:项目打包输出文件的名称,默认为${project.artifactId}${project.version}.

参考

https://blog.csdn.net/fly910905/article/details/79119349

https://www.cnblogs.com/willvi624/p/9456239.html