1.将pom.xml中的打包方式修改为war
<groupId>com.borya</groupId> <artifactId>Project</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging>
2.在pom.xml中添加依赖,将scope状态修改为provided
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
3.修改src/main/java下的application启动项
package com.borya; @SpringBootApplication public class ProjectApplication extends SpringBootServletInitializer implements WebApplicationInitializer{ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application){ return application.sources(ProjectApplication.class); } public static void main(String[] args) { SpringApplication.run(ProjectApplication.class, args); } }
4.重新build项目
5.菜单 Build -->> build artifacts -->> all artifacts -->> Build
6.此时项目已经成功打包成war包,位置在项目结构的target下,以.war结尾的就是项目
7.下面就是将项目发布到远程服务器上了,我这里使用的是WinSCP工具,登录成功后,直接将war包放到服务器tomcat下的webapps中,修改tomcat/conf中的server.xml
8.找到Host标签,在其中添加如下配置
<Context docBase="包名.war" path="/demo3" reloadable="true" debug="0" privileged="true" />
9.重启tomcat
重启可以理解为先关闭tomcat+再启动tomcat
sh shutdown.sh sh startup.sh
原文地址:https://www.cnblogs.com/valu/p/8401728.html
时间: 2024-10-20 21:16:39