当前位置: 首页 > news >正文

SpringBoot3设置maven package直接打包成二进制可执行文件

注意事项

SpringBoot普通native打包顺序clean compile spring-boot:process-aot native:compile
使用以下配置只会的打包顺序clean package(注意:使用此配置以后打包会有编译后的class文件、jar包、original源文件、二进制可执行文件【Linux是无后缀的包名,Windows是exe】)

pom.xml

<build><plugins><!-- AOT Graalvm native maven 插件 --><plugin><groupId>org.graalvm.buildtools</groupId><artifactId>native-maven-plugin</artifactId><version>${native.maven.plugin.version}</version><extensions>true</extensions><executions><execution><id>build-native</id><goals><!-- <goal>compile-no-fork</goal>(不推荐使用) --><goal>compile</goal></goals><!-- 让mvn package 直接打包成二进制可执行文件的主要配置 --><phase>package</phase></execution><execution><id>test-native</id><goals><goal>test</goal></goals><!-- mvn test 测试 native(如果skipTests,这里也会跳过!) --><phase>test</phase></execution></executions><configuration><!-- main 文件 --><mainClass>com.meta39.springboot3demo.SpringBoot3DemoApplication</mainClass><!-- 快速构建【CPU和内存疯涨,这时候电脑会卡顿】或者将 GRAALVM_QUICK_BUILD 环境变量设置为 true --><quickBuild>true</quickBuild><skipNativeTests>true</skipNativeTests><debug>false</debug><verbose>false</verbose><buildArgs combine.children="append"><buildArg>--enable-url-protocols=http</buildArg></buildArgs><jvmArgs><!-- 单独设置编译进程内存 -Xms 和 -Xmx(不设置的话,有多少用多少。推荐不设置) -->
<!--                        <arg>-Xms4G</arg>-->
<!--                        <arg>-Xmx4G</arg>--></jvmArgs></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><annotationProcessorPaths><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></path></annotationProcessorPaths></configuration></plugin><!-- Spring Boot Maven 插件【前面设置了版本就会替换掉 spring-boot-maven-plugin 里默认的版本号】 --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><!-- 不设置 process-aot 可能无法打成 native ,因为Spring boot 用了很多反射,需要 aot 优化后才能成功打成native --><id>process-test-aot</id><goals><goal>process-test-aot</goal></goals></execution></executions></plugin></plugins></build>

进阶

不使用上面的配置,使用命令打包。

mvn clean compile spring-boot:process-aot native:compile -DskipTests -Dmaven.compile.fork=true -T 1C -f pom.xml -Pprod

相关文章:

  • 开源项目FastAPI-MCP:一键API转换MCP服务
  • 软件测试笔记(测试的概念、测试和开发模型介绍、BUG介绍)
  • 计算机视觉7——齐次坐标与相机内外参
  • 测试模版1
  • 【Python笔记 01】变量、标识符
  • Eureka搭建
  • Vue3 + TypeScript,关于item[key]的报错处理方法
  • 2025年4月19日-得物算法岗春招笔试题-第一题
  • HBase安装与基本操作指南
  • 【21天学习打卡挑战赛】如何学习WEB安全:逼自己在短时间掌握WEB安全核心内容
  • 【Linux我做主】GDB调试工具完全指南
  • CSS值和单位
  • 跟我学C++中级篇——程序中的临时文件的处理
  • [原创](现代C++ Builder 12指南): [4]如何使用VCL的TStringBuilder?
  • Java 网络编程性能优化:高吞吐量的实现方法
  • MAC-QueryWrapper中用的exists,是不是用join效果更好
  • 【OSG学习笔记】Day 4: 相机与视口——控制观察视角
  • 生成对抗网络(Generative adversarial network——GAN)
  • 深度学习相关技术
  • 在 Anaconda 上安装多版本 Python 解释器并在 PyCharm 中配置
  • 人民日报读者点题·共同关注:花粉过敏增多,如何看待城市绿化“成长的烦恼”
  • 大尺度色情语聊、撮合卖淫嫖娼!一些交友软件暗藏“桃色陷阱”
  • 寒武纪一季度营收猛增42倍,净利3.55亿元,连续两个季度盈利
  • 老人在健身中心晕倒获AED急救,上海检察机关为何被感谢?
  • 上海浦东召开高水平改革开放推进会,综合型企业出海服务平台启动
  • 科技如何赋能社会治理?帮外卖员找新家、无人机处理交通事故……