У нас часто есть такой сценарий, нам просто нужно сделать 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> <exec> <id> exec </id> <phase> package </phase> <come> <gule> jar </gule> </oal> <ficureturation> <slassifier> exec </classicifier> </configuration> </execution> <seecution> <phase> Пакет </phase> <ogle> <gule> jar </oal> </ogle> <ficureturation> <!-Нужно, чтобы это было обеспечено. <forcecreation> true </forcecreation> <concellides> <concloaded> application.yml </exclide> </excludes> </configuration> </выполнение> </receoming> </plugin> </plugins> </build>
Выполнить MVN Clean Package
Localhost: Spring-Boot-Tutorial-Non-Executable Majunwei $ MVN Clean Package [Info] Сканирование для проектов ... [ПРЕДУПРЕЖДЕНИЕ] [ПРЕДУПРЕЖДЕНИЕ] Были столкнулись некоторые проблемы при создании эффективной модели для Com.majunwei: Spring-Boot-tutorial-non-executable: jar: 0.0.1-snapshot [Warning] 'for leprugn.plugin.pluginable. org.apache.maven.plugins: Maven-Jar-Plugin отсутствует. @ com.majunwei: Spring-boot-tutorial-non-executable: [Unknown-version], /users/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/pom.xml, линия 26, колонка 17 org.springframework.boot: Spring-Boot-Maven-Plugin отсутствует. @ com.majunwei: Spring-boot-tutorial-non-executable: [Неизвестно-версия], /сарс/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/pom.xml, строка 19, колонка 17 [предупреждение] [предупреждение]. [Предупреждение] [Информация] [Информация] -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /Пользователи/Majunwei/Documents/Work/Spring-Boot-Tutorial/Spring-Boot-Tutorial-Non-Executable/Target [Info] [Info] --- Maven-Resources-Plugin: 2.6: Ресурсы (по умолчанию-ресурсы) @ Spring-Boot-Tutorial-Non-Executable --- Использование INFO. Maven-Compiler-Plugin: 3.1: Compile (по умолчанию Compile) @ Spring-Boot-Tutorial-Non-Executable --- [Info] Обнаруженные изменения-перекомпиляция модуля! Maven-Resources-Plugin: 2.6: Testresources (по умолчанию stestresources) @ Spring-boot-tutorial-non-excectable --- [info] Использование «UTF-8 'Кодирование для копирования фильтрованных ресурсов. /Пользователи/Majunwei/Documents/Work/Spring-Boot-Tutorial/Spring-Boot-Tutorial-Non-Executable/SRC/Test/Resources [Info] [Info] --- Maven-Compiler-Plugin: 3.1: TestCompile (по умолчанию-testcompile) @ @ info [info] @ info [info] @ info [info] @ Maven-Surefire-Plugin: 2.12.4: тест (тест по умолчанию) @ spring-boot-tutorial-non-executible --- [info] Нет тестов для работы. /Ousers/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-non-executable/target/spring-boot-tutorial-non-executable-0.0.1-snapshot.jar---bootable] [Info] ---- Maven-Jar-Plugin: 2.4: jar (executail ---[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.jarrinfo] ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2017-08-07T18:22:50+08:00[INFO] Final Memory: 17M/174M[INFO] ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Загрузите исходный код экземпляра
Выше всего содержание этой статьи. Я надеюсь, что это будет полезно для каждого обучения, и я надеюсь, что все будут поддерживать Wulin.com больше.