当前位置: 首页 > news >正文

IDEA中使用tomcat8-maven-plugin插件

第一种方式

pom.xml

<?xml version="1.0" encoding="UTF-8"?><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"><modelVersion>4.0.0</modelVersion><groupId>edu.finance</groupId><artifactId>test-tomcat8</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><dependencies><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency></dependencies><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><build><finalName>ssm</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat8-maven-plugin</artifactId><version>3.0-r1655215</version>
<!--          <configuration>-->
<!--            <port>8080</port>-->
<!--            <path>/</path>-->
<!--            <uriEncoding>${project.build.sourceEncoding}</uriEncoding>-->
<!--          </configuration>--></plugin></plugins></pluginManagement></build><!--配置Tomcat8仓库--><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><!--这个google的用不了--><!--<pluginRepository><id>beardedgeeks-releases</id><url>http://beardedgeeks.googlecode.com/svn/repository/releases</url></pluginRepository>--></pluginRepositories>
</project>

运行

在这里插入图片描述

输入命令

mvn tomcat8:run-war

在这里插入图片描述

运行成功
在这里插入图片描述

报错信息

参考
https://www.jianshu.com/p/4944d7d503a1

问题一:找不到 rt.jar

使用 tomcat8:run 时,有可能会出现如下错误:

Caused by: java.io.FileNotFoundException: C:\Program%20Files\Java\jdk1.8.0_201\jre\lib\rt.jar (系统找不到指定的路径。)

这是因为 tomcat8-maven-plugin 运行时需要查找、使用 rt.jar ,但是它所在的路径名中有空格(上述的 %20)对 tomcat8-maven-plugin 造成了干扰。

tip 解决方案

使用的是 tomcat8:run-war 命令运行项目。

问题二:访问后台遇到 500 错误

使用 tomcat8:run 时,有可能会出现莫名其妙的 500 错误。
在这里插入图片描述

tip 解决方案

使用的是 tomcat8:run-war 命令运行项目。

问题三:找不到 javax.inject-1.jar

使用 tomcat8:run-war 时,有可能会遇到如下问题( 猜测是和 IDEA 的版本有关,我在使用 2021.2.2 等高版本之后就没有遇到这个问题了 )。

Caused by: java.io.FileNotFoundException: C:\Program%20Files\JetBrains\IntelliJ%20IDEA%202020.2.3\plugins\maven\lib\maven3\lib\javax.inject-1.jar (系统找不到指定的路径。)

这是因为 IDEA 所使用的内置的 maven 的路径名中有空格(上述的 %20)对 tomcat8-maven-plugin 造成了干扰(对 tomcat7-maven-plugin 没影响)。

tip 解决方案

万一遇到了这个问题,你需要将 IDEA 所使用的 maven 从内置的 maven 配置为外部的 maven ,而且这个 maven 的路径中不能有空格。

第二种

下面仓库有Tomcat8

https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin
https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin/3.0-r1655215

在这里插入图片描述

或者

https://artifacts.alfresco.com/nexus/

在这里插入图片描述

pom

<?xml version="1.0" encoding="UTF-8"?><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"><modelVersion>4.0.0</modelVersion><groupId>edu.finance</groupId><artifactId>test-tomcat81</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><!-- https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin --><dependencies><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency>
<!--    <dependency>-->
<!--      <groupId>org.apache.tomcat.maven</groupId>-->
<!--      <artifactId>tomcat8-maven-plugin</artifactId>-->
<!--      <version>3.0-r1655215</version>-->
<!--    </dependency>--></dependencies><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat8-maven-plugin</artifactId><version>3.0-r1655215</version><configuration><port>80</port><path>/</path></configuration></plugin></plugins></build><!--配置Tomcat8仓库--><pluginRepositories><pluginRepository><id>alfresco</id><url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url></pluginRepository></pluginRepositories>
</project>

“tomcat8:run” 爱报各种错误,建议使用“tomcat8:run war”
在这里插入图片描述
如果不想启动的时候太麻烦,可以在右上角工具点击“Edit Configurations”

点击“+”,Maven ,可以命名为tomcat8,这样可以直接点击,不用再找到“tomcat8:run”

http://www.lryc.cn/news/8239.html

相关文章:

  • 2023年妇女节是哪一天 妇女节是2023年几月几日?
  • 如何运维多集群数据库?58 同城 NebulaGraph Database 运维实践
  • 尚医通(十四)Spring Cloud GateWay网关 | 跨域 | 权限认证
  • PO模式在Selenium中简单实践
  • KubeSphere
  • JAVA基础阶段面试题(关键点)必备
  • Shiro简介
  • cmu 445 poject 3笔记
  • CHAPTER 2 Zabbix界面操作
  • keep-alive的使用-及遇到的问题
  • 华为OD面试经验分享,尤其注意机试题部分
  • 【Java】String、StringBuffer、StringBuilder的区别
  • iOS开发:对Block使用的一次研究总结
  • Spark 3.1.1 shuffle fetch 导致shuffle错位的问题
  • 2月第2周榜单丨飞瓜数据B站UP主排行榜(哔哩哔哩平台)发布!
  • Jdk19 动态编译 Java源码为 Class 文件
  • 安装 GPU 版本的 tensorflow 完整版本
  • BOM编程-设置地址栏上的URL
  • 设计模式之原型模式与建造者模式详解和应用
  • C语言(函数和递归)
  • 快乐的shell命令行
  • 大数据面试题flume篇
  • 零信任-深信服零信任aTrust介绍(5)
  • UVa 1343 The Rotation Game 旋转游戏 IDA* BFS 路径还原
  • 硬件学习 软件Cadence day02 画原理图的基本操作 (键盘快捷键 , 原理图设计流程 , 从开始到导出网表流程)
  • 【python】基于Socket的聊天室Python开发
  • 2023想转行软件测试的看过来,你想要了解的薪资、前景、岗位方向、学习路线都讲明白了
  • TortoiseSVN的使用
  • 操作系统(day09) -- 连续分配管理方式
  • APISpace 带你一起走进西湖美景