当前位置: 首页 > 知识库问答 >
问题:

从1.5.8版本到2.1.14版本的Spring Boot迁移后,BootJar没有创建BOOT-INF文件夹

何博涛
2023-03-14

我已经将Spring Boot应用程序从1.5.8迁移到2.1.14版本,并使用gradle作为构建脚本。我正在使用spring boot gradle插件和spring boot依赖关系管理插件。在我们的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
//        customConfiguration = "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
//        customConfiguration = "zuulconfiguration"
//        withJarTask = eztrackerApiGatewayJar
}


bootJar.dependsOn = [eurekaBoot, oAuthConfigJarBoot]

bootJar.enabled = false

在上面的代码执行任何gradle汇编后,它创建了两个可执行的jar文件eurekaJar-0.0.1.jar,oAuthConfigJar-0.0.1.jar.

我的问题是:

在spring boot迁移之前,在上述JAR中,文件夹结构如下:

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没有运行。

如有任何评论,我们将不胜感激。

共有1个答案

云宝
2023-03-14

您应该配置引导jar任务的类路径,而不是使用from将文件直接添加到jar。类路径上的Jar文件将打包在BOOT-INF/lib中,目录将打包在BOOT-INF/classes中。

作为参考,您可以在这里看到Spring Boot如何在自己的插件中配置默认bootJar任务的类路径。从上面显示的内容来看,您可能也希望使用主源集的运行时类路径。

这是您的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
 类似资料:
  • 在尝试迁移到spring boot 2.0版时,我在尝试运行JUnits时遇到了以下问题。同样的单元测试曾经在spring boot版本1.5.8上工作,但是在更改版本之后,它们开始失败。下面是对问题的堆栈跟踪。你能告诉我这件事的根本原因是什么吗? null null

  • 本文向大家介绍迁移PHP版本到PHP7,包括了迁移PHP版本到PHP7的使用技巧和注意事项,需要的朋友参考一下 今天看到微博上说phpng也就是php7合并到master上了,大家都知道我是比较喜欢探讨最新版本的东西,看看有什么特性,我就忍不住升级去了,以前我的PHP版本是5.5.19,然后我就开始了。 然后编译配置参数,我的博客服务器是腾讯云服务器,因为是博客配置比较低。如下: 下边是针对php

  • 可悲的是,这些来源中引用的大多数轴突迁移指南和文档已经过时或被删除。 外面还有移民指南吗?另外,哪种方法更好--一次迁移还是两步迁移?有Axon经验的人可以分享他们的来源或见解吗?

  • 迁移CVS版本库到Subversion 或许让CVS用户熟悉Subversion最好的办法就是让他们的项目继续在新系统下工作,这可以简单得通过平淡的把CVS版本库的导出数据导入到Subversion完成,或者是更加完全的方案,不仅仅包括最新数据快照,还包括所有的历史,从一个系统到另一个系统。这是一个非常困难的问题,包括推导保持原子性的修改集,转化两个系统完全不同的分支政策。但是我们还是有许多工具声

  • 最近,我们开始将应用程序从 websphere-liberty 16.0.0.2 迁移到版本 17.0.0.2(在这两种情况下都使用 javaee7 配置文件)。在服务器中使用相同的 SSL 配置.xml由于 SSL 握手失败,应用程序无法通过 https 调用远程静止服务。这是我的服务器.xml websphere-free v.16server.xml的唯一区别是没有启用transportSe

  • Mercurial(水银)是和Git同时代的、与之齐名的一款著名的分布式版本控制系统,也有相当多的使用者。就像水银又名汞,作为版本控制系统的Mercurial又称作Hg(水银元素符号)。Hg具有简单易用的优点,至少Hg提交的顺序递增的数字编号让Subversion用户感到更为亲切。Hg的开发语言除少部分因性能原因使用C语言外,大部分用Python语言开发完成,因而更易扩展,最终形成了Hg最具特色的