创建Maven Webapp项目
创建后的项目结构
index.jsp文件
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
pom.xml配置
添加tomcat7插件
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/web</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
</configuration>
</plugin>
</plugins>
</build>
右键项目,运行方式—>运行配置
运行结果
打开浏览器输入网址localhost:8080/web/index.jsp
(路径和端口由pom.xml文件的path属性和port属性配置)