修改pom.xml文件:
增加
<packaging>jar</packaging>
增加build配置:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.example.tioncico.TioncicoApplication</mainClass><!--自己项目的启动类--> </configuration> </plugin> </plugins> </build>
修改启动类:
package com.example.tioncico; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; //springboot 应用启动类的标识 @SpringBootApplication //继承SpringBootServletInitializer 用于springboot内部启动tomcat,并且可自定义端口号,项目名 public class TioncicoApplication extends SpringBootServletInitializer { public static void main(String\[\] args) { SpringApplication.run(TioncicoApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(this.getClass()); } }
maven编译打包
编译打包成功之后,会在根目录生成target目录:
使用java -jar ./target/xxx.jar即可运行:
修改端口
在appliation.properties 中增加:
server.port=9090
重新打包即可根据新端口运行: