Gradle: Build fat jar mit Spring Boot Dependencies
Ich bin mit Gradle bauen und Paket einen sehr einfachen spring-boot-Anwendung (99% statische Inhalte) in ein Glas mit eingebetteten tomcat.
Habe ich versucht zu erstellen, sagte jar, zunächst das Ergebnis war 86k und nicht starten, weil es fehlt, einige Spring-boot-Klassen. Ich Schloss das Glas ich machte, enthielt keine der Abhängigkeiten der Anwendung, und da wollte ich ein in sich komplett geschlossenes Gefäß, ich sollte mehr tun, Forschung.
Dies ist, wenn ich vor der Beratung fügen Sie die from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
Abschnitt zu den "jar", die bewirkt, dass es pull-in allen Abhängigkeiten. (Hoffe ich). Ich bin vertraut mit der Idee des ternären operator, und ich kann sehen, was es hier zu tun versuchen.
Leider ist es immer noch nicht funktioniert! Hier ist der Fehler, bekomme ich beim starten, und unten ist mein build.gradle.
Ich möchte eine spring-boot-Anwendung mit embedded tomcat vollständig enthalten in einem Glas. Mache ich etwas höchst unkonventionelle?
Jede Hilfe zu diesem Zeitpunkt wäre sehr dankbar.
(About 80 lines of successful Spring Boot launch messages followed immediately by:
18:16:54.890 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132) [SpringWsTest1.jar:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[SpringWsTest1.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958) [SpringWsTest1.jar:na]
at ws.Application.main(Application.java:11) [SpringWsTest1.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:182) [SpringWsTest1.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:155) [SpringWsTest1.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:129) [SpringWsTest1.jar:na]
... 7 common frames omitted
18:16:54.891 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3b084709: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,application,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,demoController,greetingController,org.springframework.boot.autoconfigure.AutoConfigurationPackages]; root of factory hierarchy
18:16:54.891 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132) ~[SpringWsTest1.jar:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[SpringWsTest1.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117) ~[SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) [SpringWsTest1.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958) [SpringWsTest1.jar:na]
at ws.Application.main(Application.java:11) [SpringWsTest1.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:182) ~[SpringWsTest1.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:155) ~[SpringWsTest1.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:129) ~[SpringWsTest1.jar:na]
... 7 common frames omitted
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
at ws.Application.main(Application.java:11)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:182)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:155)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:129)
... 7 more
bauen.gradle ich bin mit:
println System.getProperty("java.home")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
manifest {
attributes 'Main-Class': 'ws.Application'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
Du musst angemeldet sein, um einen Kommentar abzugeben.
Brauchen Sie nicht, um sich zusätzliche gradle-Konfigurationen für den Aufbau einer fat-jar-Artefakt des spring-boot-Anwendung, da Sie eine gradle spring boot plugin. Es hat schon eine Aufgabe
bootRepackage
um es für Sie tun. Sie können darüber Lesen Sie in den offiziellen user-guide hier und hier.Löschen Sie einfach alles, was Sie getan haben, um das entpacken Abhängigkeiten Inhalt und verwenden Sie diese Aufgabe, um eine einzelne jar-Datei mit Ihrer Anwendung.
Durch die Art und Weise, können Sie daran interessiert zu schauen, eine andere Lösung, die möglicherweise bieten könnte, ein besseres Archiv-Größen, die Sie Lesen können, über eine von Ihnen, die als Kapsel bezeichnet, in diesem Artikel.
Mit aktuellen Versionen von gradle, fügen Sie diese an der Spitze Ihrer
build.gradle
Datei:dann nur
gradle build
- Sie brauchen nicht, nichts mehr zu machen.Sehen dieses plugin homepage zu finden die neueste version.