Java Web添加Tomcat Plugin启动

在Java Web项目中添加Tomcat Plugin就可以像Springboot项目一样方便的启动。
可以选择添加Tomcat7或者Tomcat8插件

Tomcat7 Plugin

  1. 在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>
  1. 配置启动
    步骤:
    Edit Configurations -》 + -》 maven
    在Name写项目名,在 Parameters tab页 中配置
    Working directory: C:/Users/luohoujian01/project/testWeb
    Command line: clean tomcat7:run
  2. 配置完成,点击启动按钮。根url: http://localhost/testWeb/

Tomcat8 Plugin

  1. 在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>
  1. 配置启动(下方有截图指导)
    步骤:
    Edit Configurations -》 + -》 maven
    在Name写项目名,在 Parameters tab页 中配置
    Working directory: C:/Users/luohoujian01/project/testWeb
    Command line: clean tomcat8:run-war
  2. 配置完成,点击启动按钮。根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进行配置
在这里插入图片描述
③点击启动,访问项目
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值