EN
Maven - example pom file with Spring Boot 2.4 + Tomcat 9 + JSP + Servlet 4.0 + log4j2 + Lombok + Hibernate + JPA + MySQL
5 points
In this article, we want to show an example Maven pom.xml
file configuration to use together:
- Spring Boot 2.4
- Tomcat 9 (JSP files, Servlet 4.0)
- log4j2
- Lombok
- Hibernate + JPA + JPA 2 Metamodel Generator
- MySQL
-
JUnit 4
-
WAR package output
Note: the below configuration enables automatic pre-compilation for Lombok and Metamodel Generator.
Run
mvn clean install package
to build the executablewar
file.
Runjava -jar target/my-project.war
to start Spring Boot Application (with Tomcat 9 that supports JSP files).
example pom.xml
file:
xxxxxxxxxx
1
2
<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">
3
<modelVersion>4.0.0</modelVersion>
4
5
<groupId>my-project</groupId>
6
<artifactId>my-project</artifactId>
7
<version>1.0</version>
8
9
<name>my-project</name>
10
<packaging>war</packaging>
11
12
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/2.4.3 -->
13
<parent>
14
<groupId>org.springframework.boot</groupId>
15
<artifactId>spring-boot-starter-parent</artifactId>
16
<version>2.4.3</version>
17
<relativePath/>
18
</parent>
19
20
<properties>
21
<java.version>1.8</java.version>
22
<spring.version>${project.parent.version}</spring.version>
23
<maven.compiler.source>${java.version}</maven.compiler.source>
24
<maven.compiler.target>${java.version}</maven.compiler.target>
25
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
27
</properties>
28
29
<dependencies>
30
31
<!-- #################### -->
32
<!-- SPRING BOOT -->
33
<!-- #################### -->
34
35
<!-- Web -->
36
<dependency>
37
<groupId>org.springframework.boot</groupId>
38
<artifactId>spring-boot-starter-web</artifactId>
39
<version>${spring.version}</version>
40
<exclusions>
41
<!-- we want to select different logger so current one is disabled -->
42
<exclusion>
43
<groupId>org.springframework.boot</groupId>
44
<artifactId>spring-boot-starter-logging</artifactId>
45
</exclusion>
46
</exclusions>
47
</dependency>
48
49
<!-- log4j2 as default spring boot logger -->
50
<dependency>
51
<groupId>org.springframework.boot</groupId>
52
<artifactId>spring-boot-starter-log4j2</artifactId>
53
<version>${spring.version}</version>
54
</dependency>
55
56
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-configuration-processor -->
57
<dependency>
58
<groupId>org.springframework.boot</groupId>
59
<artifactId>spring-boot-configuration-processor</artifactId>
60
<version>${spring.version}</version>
61
</dependency>
62
63
<!-- Web with Tomcat + Embed -->
64
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat -->
65
<dependency>
66
<groupId>org.springframework.boot</groupId>
67
<artifactId>spring-boot-starter-tomcat</artifactId>
68
<version>${spring.version}</version>
69
<scope>provided</scope>
70
</dependency>
71
72
<!-- JSTL -->
73
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
74
<dependency>
75
<groupId>javax.servlet</groupId>
76
<artifactId>jstl</artifactId>
77
<version>1.2</version>
78
</dependency>
79
80
<!-- Servlet 4.0 API -->
81
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
82
<dependency>
83
<groupId>javax.servlet</groupId>
84
<artifactId>javax.servlet-api</artifactId>
85
<version>4.0.0</version>
86
</dependency>
87
88
<!-- Need those to compile JSP -->
89
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
90
<dependency>
91
<groupId>org.apache.tomcat.embed</groupId>
92
<artifactId>tomcat-embed-jasper</artifactId>
93
<version>9.0.45</version>
94
<scope>provided</scope>
95
</dependency>
96
97
<!-- JDBC -->
98
<dependency>
99
<groupId>org.springframework.boot</groupId>
100
<artifactId>spring-boot-starter-jdbc</artifactId>
101
</dependency>
102
103
<!-- JPA -->
104
<dependency>
105
<groupId>org.springframework.boot</groupId>
106
<artifactId>spring-boot-starter-data-jpa</artifactId>
107
<version>${spring.version}</version>
108
</dependency>
109
110
<!-- Security -->
111
<dependency>
112
<groupId>org.springframework.boot</groupId>
113
<artifactId>spring-boot-starter-security</artifactId>
114
<version>${spring.version}</version>
115
</dependency>
116
117
118
<!-- #################### -->
119
<!-- MYSQL -->
120
<!-- #################### -->
121
122
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
123
<dependency>
124
<groupId>mysql</groupId>
125
<artifactId>mysql-connector-java</artifactId>
126
<version>8.0.22</version>
127
</dependency>
128
129
130
<!-- #################### -->
131
<!-- HIBERNATE -->
132
<!-- #################### -->
133
134
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
135
<dependency>
136
<groupId>org.hibernate</groupId>
137
<artifactId>hibernate-core</artifactId>
138
<version>5.4.17.Final</version>
139
</dependency>
140
141
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
142
<dependency>
143
<groupId> org.hibernate.validator</groupId>
144
<artifactId>hibernate-validator</artifactId>
145
<version>6.1.5.Final</version>
146
</dependency>
147
148
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
149
<dependency>
150
<groupId>org.hibernate</groupId>
151
<artifactId>hibernate-entitymanager</artifactId>
152
<version>5.4.17.Final</version>
153
</dependency>
154
155
<dependency>
156
<groupId>org.hibernate</groupId>
157
<artifactId>hibernate-jpamodelgen</artifactId>
158
<version>5.4.27.Final</version>
159
<scope>provided</scope>
160
<optional>true</optional>
161
</dependency>
162
163
164
<!-- #################### -->
165
<!-- TESTING -->
166
<!-- #################### -->
167
168
<!-- https://mvnrepository.com/artifact/junit/junit -->
169
<dependency>
170
<groupId>junit</groupId>
171
<artifactId>junit</artifactId>
172
<version>4.13.1</version>
173
</dependency>
174
175
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
176
<!-- Date (Jan 21, 2017) -->
177
<dependency>
178
<groupId>org.assertj</groupId>
179
<artifactId>assertj-core</artifactId>
180
<version>3.6.2</version>
181
</dependency>
182
183
184
<!-- #################### -->
185
<!-- OTHER THINGS -->
186
<!-- #################### -->
187
188
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
189
<dependency>
190
<groupId>com.google.guava</groupId>
191
<artifactId>guava</artifactId>
192
<version>27.0.1-jre</version>
193
</dependency>
194
195
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
196
<dependency>
197
<groupId>org.projectlombok</groupId>
198
<artifactId>lombok</artifactId>
199
<version>1.18.6</version>
200
<scope>provided</scope>
201
</dependency>
202
203
</dependencies>
204
205
<!-- https://github.com/dirask/spring-boot-web-jsp-example -->
206
<build>
207
<finalName>${project.artifactId}</finalName>
208
<plugins>
209
<plugin>
210
<groupId>org.apache.maven.plugins</groupId>
211
<artifactId>maven-compiler-plugin</artifactId>
212
<version>3.7.0</version>
213
<configuration>
214
<annotationProcessorPaths>
215
<path>
216
<groupId>org.projectlombok</groupId>
217
<artifactId>lombok</artifactId>
218
<version>1.18.6</version>
219
</path>
220
<path>
221
<groupId>org.hibernate</groupId>
222
<artifactId>hibernate-jpamodelgen</artifactId>
223
<version>5.4.27.Final</version>
224
</path>
225
</annotationProcessorPaths>
226
<source>${maven.compiler.source}</source>
227
<target>${maven.compiler.target}</target>
228
<verbose>true</verbose>
229
</configuration>
230
</plugin>
231
<plugin>
232
<groupId>org.springframework.boot</groupId>
233
<artifactId>spring-boot-maven-plugin</artifactId>
234
</plugin>
235
</plugins>
236
</build>
237
238
</project>