Maven生成的Spring项目部署至Tomcat 9失败求助
解决Tomcat部署时找不到Maven构建产物的问题
从你提供的堆栈信息来看,核心问题很明确:IntelliJ找不到Maven构建后生成的games解压目录或者games.war包,导致Tomcat部署失败。我给你几个实用的排查和解决步骤:
1. 先确认Maven是否成功构建了项目
首先要排除Maven本身的构建问题:
- 打开终端,切换到你的项目根目录(
C:\Users\Tobi\IdeaProjects\games),执行命令:mvn clean package - 观察构建过程是否有报错,如果有编译错误、依赖下载失败之类的提示,先解决这些问题——只有Maven成功构建,才会在
target目录生成部署需要的文件。 - 构建完成后,手动去
target目录查看,是否存在games.war文件或者games(解压后的war目录)。如果没有,那问题出在Maven构建环节,先搞定这个。
2. 检查IntelliJ的Tomcat部署配置
如果Maven已经生成了产物,那大概率是IntelliJ的部署路径配置错了:
- 打开IntelliJ的「Run/Debug Configurations」(右上角运行按钮旁边的下拉框,选择Edit Configurations);
- 找到你的Tomcat 9配置,切换到「Deployment」标签页;
- 查看已添加的Artifact:
- 如果是部署
war exploded,确认Artifact的输出路径是C:\Users\Tobi\IdeaProjects\games\target\games; - 如果是部署
war包,确认路径是C:\Users\Tobi\IdeaProjects\games\target\games.war;
- 如果是部署
- 如果路径不对,删除当前的Artifact,重新添加正确的选项(注意看Artifact名称后的后缀,比如
games:war exploded或者games:war)。
3. 验证IntelliJ的Maven配置
有时候IntelliJ的Maven配置会导致构建异常:
- 打开「File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven」;
- 确认「Maven home directory」是你本地安装的Maven版本(而非IntelliJ自带的,自带版本偶尔会有兼容性问题);
- 同时检查「User settings file」和「Local repository」的路径是否正确;
- 可以尝试点击右侧Maven面板的「clean」和「package」按钮,重新构建项目,之后再尝试部署。
4. 清理IntelliJ缓存重试
缓存问题有时候也会导致路径识别异常:
- 点击「File -> Invalidate Caches...」;
- 选择「Invalidate and Restart」,等待IDE重启后,重新构建并部署项目。
附你提供的错误日志:
Connected to server [2018-05-18 10:22:43,232] Artifact games:war exploded: Artifact is being deployed, please wait... [2018-05-18 10:22:43,232] Artifact games:war: Artifact is being deployed, please wait... [2018-05-18 10:22:43,238] Artifact games:war exploded: Error during artifact deployment. See server log for details. [2018-05-18 10:22:43,238] Artifact games:war exploded: com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: C:\Users\Tobi\IdeaProjects\games\target\games not found for the web module. [2018-05-18 10:22:43,244] Artifact games:war: Error during artifact deployment. See server log for details. [2018-05-18 10:22:43,245] Artifact games:war: com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: C:\Users\Tobi\IdeaProjects\games\target\games.war not found for the web module. 18-May-2018 22:22:52.920 INFORMATION [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\entwicklung\apache-tomcat-9.0.8\webapps\manager] 18-May-2018 22:22:53.139 INFORMATION [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\entwicklung\apache-tomcat-9.0.8\webapps\manager] has finished in [218] ms
内容的提问来源于stack exchange,提问作者gigashark
相关产品推荐
相关产品推荐

