写在前面
上篇文章 使用 Intellij IDEA 新建一个 Servlet 项目 ,文章中如何在 Intellij IDEA 中启动 Tomcat 并加载 webapp,但是配置的过程十分繁琐。至少需要进行以下三项的设置:
Add Configuration
Project Structure -> Modules -> Web
Project Structure -> Artifacts -> Add Artifact
Project Structure -> Libraries -> Add Java Library
这个繁琐的过程,不是一个初学者,尤其是想要立马开始敲代码的开发者想要的。因此,我们需要一种简单可靠,能直接在 IDE 中启动并调试 webapp 的方法。
项目地址
git clone https://gitee.com/kendoziyu/code-servlet-parent.git
其中,maven-tomcat-servlet-example 是本文的项目示例。
Maven 配置文件
我们新建一个 maven-tomcat-servlet-example 工程,编写pom.xml如下:
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">
4.0.0
coderead.servlet
maven-tomcat-servlet-example
1.0-SNAPSHOT
war
3.1.0
9.0.39
org.apache.tomcat.embed
tomcat-embed-core
${tomcat.version}
provided
org.apache.tomcat.embed
tomcat-embed-jasper
${tomcat.version}
provided
Hello