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

 更新时间:2018年02月05日 16:32:07   作者:马军伟  
这篇文章主要介绍了Spring Boot创建非可执行jar包的实例教程,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

我们经常会有这种场景,只需要把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] ------------------------------------------------------------------------

下载实例源码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 关于Spring Cloud的熔断器监控问题

    关于Spring Cloud的熔断器监控问题

    Turbine是一个聚合Hystrix监控数据的工具,它可将所有相关/hystrix.stream端点的数据聚合到一个组合的/turbine.stream中,从而让集群的监控更加方便,接下来通过本文给大家介绍Spring Cloud的熔断器监控,感兴趣的朋友一起看看吧
    2022-01-01
  • Maven如何构建可执行的jar包(包含依赖jar包)

    Maven如何构建可执行的jar包(包含依赖jar包)

    这篇文章主要介绍了Maven如何构建可执行的jar包(包含依赖jar包) ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-11-11
  • spring boot jar部署控制台日志乱码的解决

    spring boot jar部署控制台日志乱码的解决

    这篇文章主要介绍了spring boot jar部署控制台日志乱码的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-09-09
  • springboot中如何配置LocalDateTime JSON返回时间戳

    springboot中如何配置LocalDateTime JSON返回时间戳

    这篇文章主要介绍了springboot中如何配置LocalDateTime JSON返回时间戳问题。具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-06-06
  • Springboot详解RocketMQ实现消息发送与接收流程

    Springboot详解RocketMQ实现消息发送与接收流程

    这篇文章主要介绍了SpringBoot整合RocketMQ实现消息发送和接收功能,我们使用主流的SpringBoot框架整合RocketMQ来讲解,使用方便快捷,本文分步骤给大家介绍的非常详细,需要的朋友可以参考下
    2022-06-06
  • Java常用面板之JScrollPane滚动面板实例详解

    Java常用面板之JScrollPane滚动面板实例详解

    这篇文章主要介绍了Java常用面板JScrollPane的简单介绍和一个相关实例,,需要的朋友可以参考下。
    2017-08-08
  • Java AES加密和解密教程

    Java AES加密和解密教程

    这篇文章主要介绍了Java AES加密和解密的相关资料,帮助大家更好的理解和学习Java,感兴趣的朋友可以了解下
    2020-12-12
  • MyBatis是如何实现日志模块的详解

    MyBatis是如何实现日志模块的详解

    这篇文章主要给大家介绍了关于MyBatis是如何实现日志模块的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者使用MyBatis具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-10-10
  • InputStream数据结构示例解析

    InputStream数据结构示例解析

    这篇文章主要为大家介绍了InputStream数据结构示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-10-10
  • 基于IntelliJ IDEA的类注释和方法注释操作

    基于IntelliJ IDEA的类注释和方法注释操作

    这篇文章主要介绍了基于IntelliJ IDEA的类注释和方法注释操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-09-09

最新评论