在Java Web项目中添加Tomcat Plugin就可以像Springboot项目一样方便的启动。
可以选择添加Tomcat7或者Tomcat8插件
Tomcat7 Plugin
- 在pom中添加如下依赖
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>80</port>
<path>/testWeb</path>
<uriEncoding>UTF-8</uriEncoding>
<server>tomcat7</server>
</configuration>
</plugin>
- 配置启动
步骤:
Edit Configurations -》 + -》 maven
在Name写项目名,在 Parameters tab页 中配置
Working directory: C:/Users/luohoujian01/project/testWeb
Command line: clean tomcat7:run - 配置完成,点击启动按钮。根url: http://localhost/testWeb/
Tomcat8 Plugin
- 在pom中添加如下依赖
<-- 配置插件仓库 --!>
<pluginRepositories>
<pluginRepository>
<id>alfresco-public</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
</pluginRepository>
<pluginRepository>
<id>alfresco-public-snapshots</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>beardedgeeks-releases</id>
<url>http://beardedgeeks.googlecode.com/svn/repository/releases</url>
</pluginRepository>
</pluginRepositories>
<-- 配置tomcat8插件 --!>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1655215</version>
<configuration>
<port>80</port>
<path>/testWeb</path>
<uriEncoding>UTF-8</uriEncoding>
<server>tomcat8</server>
</configuration>
</plugin>
- 配置启动(下方有截图指导)
步骤:
Edit Configurations -》 + -》 maven
在Name写项目名,在 Parameters tab页 中配置
Working directory: C:/Users/luohoujian01/project/testWeb
Command line: clean tomcat8:run-war - 配置完成,点击启动按钮。根url: http://localhost/testWeb/
注意:tomcat8 plugin 的 Command line 中如果配置成与tomcat7类似 tomcat8:run,在项目启动的时候没有问题,但是在使用浏览器执行http请求时会出现如下异常
其他:在网上搜索异常解决方式时,需要找到对应的关键词,否则是找不到答案的。如:上述异常,就要找到多个关键词组合查询,tomcat8 plugin等,找不到就是关键词用得不对。换关键词
启动配置截图
步骤:以tomcat8为例
Edit Configurations -》 + -》 maven
在Name写项目名,在 Parameters tab页 中配置
Working directory: C:/Users/luohoujian01/project/testWeb
Command line: clean tomcat8:run-war
3. 配置完成,点击启动按钮。根url: http://localhost/testWeb/
①点击Edit Configurations
②其他配置根据图顺序1–7进行配置
③点击启动,访问项目