gpt4 book ai didi

Spring Boot创建非可执行jar包的实例教程

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Spring Boot创建非可执行jar包的实例教程由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

我们经常会有这种场景,只需要把Spring Boot打成普通的jar包,不包含配置文件,供其他程序应用 。

本文介绍如何使用Maven将Spring Boot应用打成普通的非可执行jar包.

配置maven-jar-plugin 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
< 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打包 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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包的实例教程的文章就讲到这里了,如果你想了解更多关于Spring Boot创建非可执行jar包的实例教程的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com