Spring Boot创建非可执行jar包的实例教程
作者:马军伟 时间:2022-10-05 12:47:35
我们经常会有这种场景,只需要把Spring Boot打成普通的jar包,不包含配置文件,供其他程序应用
本文介绍如何使用Maven将Spring Boot应用打成普通的非可执行jar包。
配置maven-jar-plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>exec</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<!-- Need this to ensure application.yml is excluded -->
<forceCreation>true</forceCreation>
<excludes>
<exclude>application.yml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
执行mvn clean package打包
localhost:spring-boot-tutorial-non-executable majunwei$ mvn clean package
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.majunwei:spring-boot-tutorial-non-executable:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ com.majunwei:spring-boot-tutorial-non-executable:[unknown-version], /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/pom.xml, line 26, column 17
[WARNING] 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ com.majunwei:spring-boot-tutorial-non-executable:[unknown-version], /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/pom.xml, line 19, column 17
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building spring-boot-tutorial-non-executable 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ spring-boot-tutorial-non-executable ---
[INFO] Deleting /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ spring-boot-tutorial-non-executable ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ spring-boot-tutorial-non-executable ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ spring-boot-tutorial-non-executable ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ spring-boot-tutorial-non-executable ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ spring-boot-tutorial-non-executable ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ spring-boot-tutorial-non-executable ---
[INFO] Building jar: /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/target/spring-boot-tutorial-non-executable-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (exec) @ spring-boot-tutorial-non-executable ---
[INFO] Building jar: /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/target/spring-boot-tutorial-non-executable-0.0.1-SNAPSHOT-exec.jar
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default) @ spring-boot-tutorial-non-executable ---
[INFO] Building jar: /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/target/spring-boot-tutorial-non-executable-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.692 s
[INFO] Finished at: 2017-08-07T18:22:50+08:00
[INFO] Final Memory: 17M/174M
[INFO] ------------------------------------------------------------------------
下载实例源码
来源:http://www.majunwei.com/view/201708072141523612.html
标签:Spring,Boot,jar包
0
投稿
猜你喜欢
TOMCAT内存溢出及大小调整的实现方法
2023-02-24 06:55:33
一文彻底搞懂Kotlin中的协程
2021-09-19 19:16:01
android JSON解析数据 android解析天气预报
2022-01-16 03:33:53
关于Springboot+gateway整合依赖并处理依赖冲突问题
2023-10-23 21:13:56
java泛型中占位符T和?有什么区别
2022-07-05 02:53:56
C# 屏蔽由于崩溃弹出的windows异常弹框
2023-08-24 04:41:57
QT5实现简单的TCP通信的实现
2023-11-02 21:24:48
C#中数组Array,ArrayList,泛型List详细对比
2023-02-22 05:44:33
C#中多态、重载、重写区别分析
2022-06-27 22:49:55
详解 c# 克隆
2021-12-16 16:23:12
Java毕业设计实战项目之在线服装销售商城系统的实现流程
2023-03-27 00:15:31
JDK动态代理,代理接口没有实现类,实现动态代理方式
2021-12-21 11:55:22
Android数字华容道小游戏开发
2023-10-06 22:31:35
C#学习笔记之适配器模式详解
2021-06-16 14:10:50
Android中View的炸裂特效实现方法详解
2022-07-25 17:59:28
Android制作漂亮自适布局键盘的方法
2022-08-04 09:14:53
JavaFx UI控件与代码间的绑定方法
2021-09-13 00:40:27
unity学习教程之定制脚本模板示例代码
2022-02-18 05:07:08
SpringBoot整合WebSocket的客户端和服务端的实现代码
2023-03-30 04:19:07
mybatisplus逻辑删除基本实现和坑点解决
2021-05-24 11:35:50