大佬教程收集整理的这篇文章主要介绍了从 1.5.8 到 2.1.14-RELEASE 的 spring boot 迁移后,BootJar 没有创建 BOOT-INF 文件夹,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经将 Spring Boot 应用程序从 1.5.8 迁移到 2.1.14-RELEASE,并使用 gradle 作为构建脚本。我正在使用 spring-boot-gradle-plugin 和 spring-boot-dependency-management 插件。在我们的 spring boot 项目中,我们通过为每个 jar 创建任务来创建多个可执行的 jar 文件,如下所示
// During Migration changed from Jar to BootJar
task eurekaappjar(type: BootJar) {
basename = 'eurekaJar'
version = '0.0.1'
println sourceSets.main.output
manifest {
attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
attributes 'Start-Class': "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
attributes 'Implementation-Version': "001"
}
bootJar {
mainClassname = "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
}
from(sourceSets.main.output) {
}
}
// During Migration changed from Jar to BootJar
task oAuthConfigJar(type: BootJar) {
basename = 'oAuthConfigJar'
version = '0.0.1'
manifest {
attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
attributes 'Start-Class': "com.abc.abcCompany.service.authserver.AuthServerApplication"
attributes 'Implementation-Version': "001"
}
springBoot {
mainClassname = "com.abcCompany.service.authserver.AuthServerApplication"
}
from(sourceSets.main.output) {
}
}
// During migration changed from BootRepackage to BootJar
task eurekaBoot(type: BootJar,dependsOn: eurekaappjar) {
mainClassname = 'com.abc.abcCompany.service.eurekaApp.EurekaApplication'
// During migration commented the below code
// customcatonfiguration = "eurekaconfiguration"
// withJarTask = eztrackerEurekaJar
}
// During migration changed from BootRepackage to BootJar
task oAuthConfigJarBoot(type: BootJar,dependsOn: oAuthConfigJar) {
println " ExecuTing eztrackerAPIGatewayBoot task"
mainClassname = 'com.abc.abcCompany.service.authserver.AuthServerApplication'
// During migration commented the below code
// customcatonfiguration = "zuulconfiguration"
// withJarTask = eztrackerAPIGatewayJar
}
bootJar.dependsOn = [eurekaBoot,oAuthConfigJarBoot]
bootJar.enabled = false
在上面的代码中,在执行任一gradle assemble后,它创建了两个可执行的jar文件eurekaJar-0.0.1.jar,oAuthConfigJar-0.0.1.jar。
这是我的问题:
spring boot迁移前,上述jars文件夹结构如下:
eurekaJar-0.0.1.jar -- org -- meta-inf -- BOOT-INT -- lib -- dependencIEs (jars) -- classes -- applicationclasses
下面是迁移后的文件夹结构
eurekaJar-0.0.1.jar -- org -- meta-inf -- applicationclasses
所以迁移后没有BOOT-INF文件夹和依赖项(lib文件夹)
由于上述问题,我的可执行 jar 没有运行。
感谢任何评论。
与其使用 from
将文件直接添加到 jar 中,不如使用 BootJar
任务中的 configure the classpath。类路径上的 Jar 文件将打包在 BOOT-INF/lib
中,目录将打包在 BOOT-INF/classes
中。
作为参考,可以在自己的插件here中查看Spring Boot是如何配置默认bootJar
任务的classpath的。从上面显示的内容来看,您可能还想使用主源集的运行时类路径。
以下是您的 eurekaAppJar
的完整示例:
import org.springframework.boot.gradle.tasks.bundling.bootJar
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
task eurekaAppJar(type: BootJar) {
basename = 'eurekaJar'
version = '0.0.1'
manifest {
attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
attributes 'Start-Class': "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
attributes 'Implementation-Version': "001"
}
mainClassName = "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
classpath sourceSets.main.runtimeClasspath
}
然后可以使用以下命令构建此 jar:
$ ./gradlew eurekaAppJar
它的类和依赖项分别打包在BOOT-INF/classes
和BOOT-INF/lib
中:
$ unzip -l build/libs/eurekaJar-0.0.1.jar
Archive: build/libs/eurekaJar-0.0.1.jar
Length Date Time Name
--------- ---------- ----- ----
0 04-04-2019 02:23 org/
0 04-04-2019 02:23 org/springframework/
0 04-04-2019 02:23 org/springframework/boot/
0 04-04-2019 02:23 org/springframework/boot/loader/
0 04-04-2019 02:23 org/springframework/boot/loader/data/
0 04-04-2019 02:23 org/springframework/boot/loader/jar/
0 04-04-2019 02:23 org/springframework/boot/loader/archive/
0 04-04-2019 02:23 org/springframework/boot/loader/util/
2688 04-04-2019 02:23 org/springframework/boot/loader/data/RandomAccessDATAFILE$DataInputStream.class
4976 04-04-2019 02:23 org/springframework/boot/loader/jar/AsciiBytes.class
540 04-04-2019 02:23 org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
3263 04-04-2019 02:23 org/springframework/boot/loader/data/RandomAccessDATAFILE$FileAccess.class
4015 04-04-2019 02:23 org/springframework/boot/loader/data/RandomAccessDATAFILE.class
945 04-04-2019 02:23 org/springframework/boot/loader/archive/Archive.class
282 04-04-2019 02:23 org/springframework/boot/loader/data/RandomAccessDATAFILE$1.class
1593 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFileEntries$1.class
299 04-04-2019 02:23 org/springframework/boot/loader/jar/JarEntryFilter.class
485 04-04-2019 02:23 org/springframework/boot/loader/data/RandomAccessData.class
616 04-04-2019 02:23 org/springframework/boot/loader/jar/Bytes.class
702 04-04-2019 02:23 org/springframework/boot/loader/jar/JarURLConnection$1.class
9854 04-04-2019 02:23 org/springframework/boot/loader/jar/JarURLConnection.class
1233 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFile$2.class
1487 04-04-2019 02:23 org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator$EntryComparator.class
3837 04-04-2019 02:23 org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator.class
1102 04-04-2019 02:23 org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
273 04-04-2019 02:23 org/springframework/boot/loader/archive/ExplodedArchive$1.class
5243 04-04-2019 02:23 org/springframework/boot/loader/archive/ExplodedArchive.class
1779 04-04-2019 02:23 org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
1081 04-04-2019 02:23 org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
7336 04-04-2019 02:23 org/springframework/boot/loader/archive/JarFileArchive.class
19737 04-04-2019 02:23 org/springframework/boot/loader/PropertiesLauncher.class
1535 04-04-2019 02:23 org/springframework/boot/loader/LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.class
4306 04-04-2019 02:23 org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
5699 04-04-2019 02:23 org/springframework/boot/loader/LaunchedURLClassLoader.class
1374 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFile$JarFileType.class
2062 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFile$1.class
2046 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
14010 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFileEntries.class
3116 04-04-2019 02:23 org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
1813 04-04-2019 02:23 org/springframework/boot/loader/jar/ZipInflaterInputStream.class
302 04-04-2019 02:23 org/springframework/boot/loader/archive/Archive$Entry.class
437 04-04-2019 02:23 org/springframework/boot/loader/archive/Archive$EntryFilter.class
3662 04-04-2019 02:23 org/springframework/boot/loader/jar/JarEntry.class
5267 04-04-2019 02:23 org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
4624 04-04-2019 02:23 org/springframework/boot/loader/jar/CentralDirectoryParser.class
11548 04-04-2019 02:23 org/springframework/boot/loader/jar/Handler.class
3650 04-04-2019 02:23 org/springframework/boot/loader/jar/StringSequence.class
345 04-04-2019 02:23 org/springframework/boot/loader/jar/FileHeader.class
15076 04-04-2019 02:23 org/springframework/boot/loader/jar/JarFile.class
1953 04-04-2019 02:23 org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
1484 04-04-2019 02:23 org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
266 04-04-2019 02:23 org/springframework/boot/loader/PropertiesLauncher$1.class
4684 04-04-2019 02:23 org/springframework/boot/loader/Launcher.class
1502 04-04-2019 02:23 org/springframework/boot/loader/MainMethodRunner.class
3608 04-04-2019 02:23 org/springframework/boot/loader/ExecutableArchiveLauncher.class
1721 04-04-2019 02:23 org/springframework/boot/loader/WarLauncher.class
1585 04-04-2019 02:23 org/springframework/boot/loader/JarLauncher.class
5203 04-04-2019 02:23 org/springframework/boot/loader/util/SystemPropertyUtils.class
0 07-15-2021 13:15 META-INF/
288 07-15-2021 13:15 META-INF/MANIFEST.MF
0 07-15-2021 13:15 BOOT-INF/
0 07-15-2021 13:15 BOOT-INF/classes/
0 07-15-2021 13:15 BOOT-INF/classes/com/
0 07-15-2021 13:15 BOOT-INF/classes/com/example/
0 07-15-2021 13:15 BOOT-INF/classes/com/example/so68382900/
745 07-15-2021 13:15 BOOT-INF/classes/com/example/so68382900/DemoApplication.class
1 07-15-2021 13:14 BOOT-INF/classes/application.properties
0 07-15-2021 13:15 BOOT-INF/lib/
398 07-15-2021 13:15 BOOT-INF/lib/spring-boot-starter-2.1.4.RELEASE.jar
1262787 07-15-2021 13:15 BOOT-INF/lib/spring-boot-autoconfigure-2.1.4.RELEASE.jar
952263 07-15-2021 13:15 BOOT-INF/lib/spring-boot-2.1.4.RELEASE.jar
407 07-15-2021 13:15 BOOT-INF/lib/spring-boot-starter-logging-2.1.4.RELEASE.jar
26586 06-26-2020 11:02 BOOT-INF/lib/javax.Annotation-api-1.3.2.jar
1099880 07-15-2021 13:15 BOOT-INF/lib/spring-context-5.1.6.RELEASE.jar
369018 07-15-2021 13:15 BOOT-INF/lib/spring-aop-5.1.6.RELEASE.jar
673302 07-15-2021 13:15 BOOT-INF/lib/spring-beans-5.1.6.RELEASE.jar
280482 07-15-2021 13:15 BOOT-INF/lib/spring-expression-5.1.6.RELEASE.jar
1293481 07-15-2021 13:15 BOOT-INF/lib/spring-core-5.1.6.RELEASE.jar
301298 07-15-2021 13:15 BOOT-INF/lib/snakeyaml-1.23.jar
290339 06-26-2020 11:01 BOOT-INF/lib/logBACk-classic-1.2.3.jar
17522 07-15-2021 13:15 BOOT-INF/lib/log4j-to-slf4j-2.11.2.jar
4589 07-15-2021 13:15 BOOT-INF/lib/jul-to-slf4j-1.7.26.jar
23762 07-15-2021 13:15 BOOT-INF/lib/spring-jcl-5.1.6.RELEASE.jar
471901 06-26-2020 11:01 BOOT-INF/lib/logBACk-core-1.2.3.jar
41139 06-26-2020 11:01 BOOT-INF/lib/slf4j-api-1.7.26.jar
266283 07-15-2021 13:15 BOOT-INF/lib/log4j-api-2.11.2.jar
--------- -------
7552715 86 files
以上是大佬教程为你收集整理的从 1.5.8 到 2.1.14-RELEASE 的 spring boot 迁移后,BootJar 没有创建 BOOT-INF 文件夹全部内容,希望文章能够帮你解决从 1.5.8 到 2.1.14-RELEASE 的 spring boot 迁移后,BootJar 没有创建 BOOT-INF 文件夹所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。