【问题标题】:Unable to change Main-Class property within Manifest.mf无法更改 Manifest.mf 中的 Main-Class 属性
【发布时间】:2021-03-02 14:47:17
【问题描述】:

我正在将 springboot 应用程序从 1.X 升级到 2.1.3.RELEASE。我的 Springboot 是一个多模块项目设置,使用类似于此的 java 命令触发。

    java -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5088 -Drun.jvmArguments="-Xdebug" -Dloader.path=C:\code\build\libs\dir\ -jar C:\code\build/libs/core.jar --spring.config.location=C:\config\application.properties

这就是项目结构的样子

  • 应用程序
    • 常见
    • Core(有主类)

升级前:core.jar的Manifest.mf文件长这样

Manifest-Version: 3.2.15.signature.LOCALDEV
Project-Name: core
Built-By: dkumar
Built-Date: 2020-11-10 16:09
Project-Version: 3.2.15.signature.LOCALDEV
Spring-Boot-Version: 1.5.1.RELEASE
Main-Class: org.springframework.boot.loader.PropertiesLauncher
Git-Branch: signature
Start-Class: com.demo.Main
Spring-Boot-Classes: BOOT-INF/classes/
Git-Commit-Hash: signature
Project-Group: com.demo.print
Spring-Boot-Lib: BOOT-INF/lib/

升级后。这是 manifest.mf 文件的样子

Manifest-Version: 3.1.87.upgradespring.LOCALDEV
Git-Branch: upgradespring
Project-Name: core
Built-By: dkumar
Built-Date: 2020-11-18 18:15
Start-Class: com.demo.Main
Git-Commit-Hash: upgradespring
Project-Group: com.demo.print
Project-Version: 3.1.87.upgradespring.LOCALDEV
Main-Class: org.springframework.boot.loader.JarLauncher

在升级之前,我的核心build.gradle 中的以下属性负责使用org.springframework.boot.loader.PropertiesLauncher,而-Dloader.path 又使用-Dloader.path 将所有Sub(子项目)jar 加载到类路径中

springBoot{
    mainClass = "com.demo.Main"
    layout = "ZIP"
}

升级后,layout 属性现在已在 2.1.3.RELEASE 中弃用,Main-Class 现在更改为Main-Class: org.springframework.boot.loader.JarLauncher,这不支持-Dloader.path 的使用(我认为)。因此,当我尝试调用 Sub 类(子项目)时,我总是得到 No bean found 错误。发生这种情况是因为 -Dloader.path 无法将子项目中的 JARS 包含到类路径中。在升级之前,我可以在类路径上看到相关的 jar。

我尝试了几种方法来更改清单中的 Main-Class 属性以使用 PropertiesLaucher,但似乎都没有奏效。我还查看了插件文档并尝试了类似的方法,但没有奏效 https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/gradle-plugin/reference/html/#packaging-executable-configuring-properties-launcher

我认为通过更改主类可以解决这个问题,但我不知道该怎么做。

任何建议或想法都会有所帮助。欢迎所有的cmets。如果需要,我会更新问题。

由于公司政策,我无法放置更大的代码 sn-p,因此我提前道歉。

【问题讨论】:

    标签: spring spring-boot build.gradle


    【解决方案1】:

    我可以通过添加以下属性来解决这个问题

        bootJar {
        manifest {
            attributes(
             'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher',
             'Spring-Boot-Classes': 'BOOT-INF/classes/',
             'Spring-Boot-Lib': 'BOOT-INF/lib/'
             )
        }
    }
    

    只有这样才能在清单中正常工作:

    'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
    

    【讨论】:

      猜你喜欢
      • 2013-11-14
      • 2014-03-12
      • 2012-12-04
      • 2013-11-06
      • 2013-03-08
      • 2020-10-13
      • 2018-01-12
      • 2019-01-31
      • 1970-01-01
      相关资源
      最近更新 更多