Spring Boot创建非可执行jar包的实例教程
我们经常会有这种场景,只需要把SpringBoot打成普通的jar包,不包含配置文件,供其他程序应用
本文介绍如何使用Maven将SpringBoot应用打成普通的非可执行jar包。
配置maven-jar-plugin
org.springframework.boot spring-boot-maven-plugin exec maven-jar-plugin exec package jar exec package jar true application.yml
执行mvncleanpackage打包
localhost:spring-boot-tutorial-non-executablemajunwei$mvncleanpackage [INFO]Scanningforprojects... [WARNING] [WARNING]Someproblemswereencounteredwhilebuildingtheeffectivemodelforcom.majunwei:spring-boot-tutorial-non-executable:jar:0.0.1-SNAPSHOT [WARNING]'build.plugins.plugin.version'fororg.apache.maven.plugins:maven-jar-pluginismissing.@com.majunwei:spring-boot-tutorial-non-executable:[unknown-version],/Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/pom.xml,line26,column17 [WARNING]'build.plugins.plugin.version'fororg.springframework.boot:spring-boot-maven-pluginismissing.@com.majunwei:spring-boot-tutorial-non-executable:[unknown-version],/Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/pom.xml,line19,column17 [WARNING] [WARNING]Itishighlyrecommendedtofixtheseproblemsbecausetheythreatenthestabilityofyourbuild. [WARNING] [WARNING]Forthisreason,futureMavenversionsmightnolongersupportbuildingsuchmalformedprojects. [WARNING] [INFO] [INFO]------------------------------------------------------------------------ [INFO]Buildingspring-boot-tutorial-non-executable0.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'encodingtocopyfilteredresources. [INFO]Copying1resource [INFO] [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@spring-boot-tutorial-non-executable--- [INFO]Changesdetected-recompilingthemodule! [INFO]Compiling1sourcefileto/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'encodingtocopyfilteredresources. [INFO]skipnonexistingresourceDirectory/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]Nothingtocompile-allclassesareuptodate [INFO] [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@spring-boot-tutorial-non-executable--- [INFO]Noteststorun. [INFO] [INFO]---maven-jar-plugin:2.4:jar(default-jar)@spring-boot-tutorial-non-executable--- [INFO]Buildingjar:/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]Buildingjar:/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]Buildingjar:/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]BUILDSUCCESS [INFO]------------------------------------------------------------------------ [INFO]Totaltime:2.692s [INFO]Finishedat:2017-08-07T18:22:50+08:00 [INFO]FinalMemory:17M/174M [INFO]------------------------------------------------------------------------
下载实例源码
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。