将 Spring Boot 项目打包成可以独立运行的 jar 包
| 环境 |
|---|
| Windows 11 Pro 23H2 OS build 22631.3447 |
| OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode, sharing) |
| Spring Boot, Java version 等版本详见正文内容 |
1. pom.xml 文件配置
1 | |
2. 在 pom.xml 文件添加插件
1 | |
3. 打包
运行如下命令,将在 .\target\ 目录内生成 xxx.jar 包
1 | |
-Dspring.profiles.active=local 用于指定打包环境的配置文件
4. 运行 jar 包
使用以下命令,可以运行 jar 包
1 | |
-Dspring.profiles.active=local 用于指定运行环境的配置文件
5. 参考
- java - SpringBoot no main manifest attribute (maven) - Stack Overflow: https://stackoverflow.com/questions/54867295/springboot-no-main-manifest-attribute-maven
- Fixing the No Main Manifest Attribute in Spring Boot | Baeldung: https://www.baeldung.com/spring-boot-fix-the-no-main-manifest-attribute
- Spring Boot Maven Plugin Documentation: https://docs.spring.io/spring-boot/docs/3.1.11/maven-plugin/reference/htmlsingle/
- java - “Unknown lifecycle phase. You must specify a valid lifecycle phase or a goal error” occurs when trying to run spring boot app with profile - Stack Overflow: https://stackoverflow.com/questions/70473772/unknown-lifecycle-phase-you-must-specify-a-valid-lifecycle-phase-or-a-goal-err
- ID: B2-W8+1.0.1
- 原文:https://blog.cc01cc.cn/2024/04/23/package-spring-boot-jar/
- 署名:零一/cc01cc(zeo): https://github.com/cc01cc/
- 本作品采用署名-相同方式共享 4.0 国际(CC BY-SA 4.0 DEED)许可证进行许可,转载请标明源地址,谢谢
将 Spring Boot 项目打包成可以独立运行的 jar 包
https://blog.cc01cc.cn/2024/04/23/package-spring-boot-jar/