Spring Boot创建非可执行jar包的实例教程
程序员文章站
2024-01-20 21:46:16
我们经常会有这种场景,只需要把spring boot打成普通的jar包,不包含配置文件,供其他程序应用
本文介绍如何使用maven将spring boot应用打成普通的非...
我们经常会有这种场景,只需要把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] ------------------------------------------------------------------------
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇: 存储过程里的递归 实现方法