【问题标题】:Could not find or load main java class jar on AWS EC2 Linux无法在 AWS EC2 Linux 上找到或加载主 java 类 jar
【发布时间】:2022-01-07 13:19:39
【问题描述】:

我需要在Linux 上运行AWS EC2jar 文件。 我在Gradle 上有一个multi-project。 我知道我的问题有很多类似物,但我没有找到 multi-project 的任何内容。

我的项目结构如下

demo
   -core
       com.example
       build.gradle
   -web
       build.gradle
       com.example
          DemoApplication.java(main)
   build.gradle

我的build.gradle 在演示中。

plugins {
    id 'org.springframework.boot' version '2.6.1'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

jar {
    manifest {
        attributes 'Main-class' : 'com.example.DemoApplication'
    }
}


configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
    implementation 'org.springframework.boot:spring-boot-starter-hateoas'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'mysql:mysql-connector-java'
    runtimeOnly 'org.postgresql:postgresql'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

test {
    useJUnitPlatform()
}

当我执行命令 jar 时,我得到了在 Linux java -jar '/home/ec2-user/demo-0.0.1-SNAPSHOT-plain.jar' 上运行的 jar 文件,它给了我一个错误。

无法找到或加载主类 com.example.DemoApplication

【问题讨论】:

    标签: java linux gradle amazon-ec2 jar


    【解决方案1】:

    因此,我对GradleSpring-boot 版本感到棘手。 我做了什么让它发挥作用:

    1. start.spring.io 中使用Java 11Spring Boot 2.5.8(SNAPSHOT) 创建了一个新项目。
    2. 将整个项目移至新项目。
    3. 我还在gradle cleangradle build 之前使用了2 个命令。在工作版本中,我使用了gradlew clean build
    4. 并像往常一样在Linux 中启动jar 文件。

    希望有一天它对某人有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-10
      • 2017-11-06
      • 2015-03-05
      • 2016-09-17
      • 1970-01-01
      • 2021-06-06
      • 2015-09-22
      相关资源
      最近更新 更多