1、确保项目配置正确
在pom.xml中,确保已经包含spring-boot-maven-plugin插件:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
添加完插件配置,点击sync maven change
更新pom文件。
注意
:使用以上配置,springboot核心依赖使用 parent 继承方式,要不然会出现找不到main主类错误,出现错误这时候需要配置启动类。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<relativePath/>
</parent>
2、执行打包生成Jar包
打开maven窗口,在Lifecycle列中,双击package打包项目
3、生成的JAR包
打包完成后,生成的JAR文件会位于target目录下,文件名通常为-.jar。例如:
target/myapp-0.0.1-SNAPSHOT.jar
4、运行JAR包
使用以下命令运行生成的JAR包:
java -jar target/myapp-0.0.1-SNAPSHOT.jar