spring-boot - Spring Boot可执行文件-主应用程序类的classnotfound错误

标签 spring-boot gradle jar

以下是我的build.gradle-我没有在https://start.spring.io/生成的样板代码上编写任何Java代码-我的问题是,我分解了发行文件夹下生成的tar文件并运行可执行jar(使用可以在分发文件夹中找到),我得到主应用程序类的classnotfound异常:

错误:找不到或加载主类com.itreatmd.emr.emrServices.EmrServicesApplication
造成原因:java.lang.ClassNotFoundException:com.itreatmd.emr.emrServices.EmrServicesApplication

我查看了lib文件夹,并在其中找到了我的胖子 jar 。如果我炸开胖子以搜索主要应用程序类,则会发现它列出为:BOOT-INF / classes / com / itreatmd / emr / emrServices / EmrServicesApplication.class。

但是,我没有看到任何spring boot loader类。在胖子里

我想我需要修改build.gradle来解决此问题,但是我找不到解决方案。

    plugins {
            id 'org.springframework.boot' version '2.2.2.BUILD-SNAPSHOT'
            id 'io.spring.dependency-management' version '1.0.8.RELEASE'
            id 'java'
            id 'distribution'
            id 'application'
    }

    group = 'com.itreatmd.emr'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '11'

    mainClassName = 'com.itreatmd.emr.emrServices.EmrServicesApplication'
    repositories {
            mavenCentral()
            maven { url 'https://repo.spring.io/milestone' }
            maven { url 'https://repo.spring.io/snapshot' }
    }

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-loader'
    implementation 'org.springframework.boot:spring-boot-starter-jersey'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}    
    bootJar {
        manifest {
            attributes 'Implementation-Title': 'Gradle Quickstart',
                       'Implementation-Version': version,
                       'Main-Class': 'com.itreatmd.emr.emrServices.EmrServicesApplication'
        }
    }
    test {
            useJUnitPlatform()
    }

最佳答案

我的问题的答案是,在最新的SprintBoot版本中,build / distribution文件夹无用。当我从旧版本的SpringBoot迁移到最新的2.x版本时,我假设我可以继续从build / distribution文件夹内的tar中提取jar,然后继续(在打包和压缩方面,tar有一些优点。分配)。但是,您发现在分发中分解tar时发现的脚本已损坏。因此,只需使用bootScripts下的脚本即可继续。

关于spring-boot - Spring Boot可执行文件-主应用程序类的classnotfound错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58822470/

相关文章:

java - jar 中的名称 SNAPSHOT 是什么意思?/*snapshot*.jars 有什么问题?

eclipse - Eclipse 中的 CLASSPATH "bootstrap entries"和 "user entries"有什么区别?

spring - 如何禁用某些资源路径的Spring Security

java - 为什么 Flux<String> 在通过 ServerResponse 返回时会折叠成单个 String,除非每个 String 元素都以 "\n"终止?

android-studio - 为Wear OS和普通应用程序构建的Android Studio项目,但共享源文件

java - 从类路径中的所有 jar 文件中提取扩展 "Randomizer"的类

java - 为什么tx注解驱动会产生冲突?

ssl - Spring Boot 调用 HTTPS 端点

Gradle 复制 installDist 上的文件夹

java - 如何授予CHMOD 0755对Jar中所有文件的权限