问题描述
我正在包装我的应用程序的影子罐。该应用程序使用kotlin和一些外部依赖项。所有依赖项都在我的jar中,但在运行时出现以下异常:
java.lang.NoSuchMethodError:java.util.Optional.isEmpty()Z
末尾的Z始终存在;我不知道它来自哪里。
我检查了多个build.gradle文件示例,我的似乎很好。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
group 'com.bancarelvalentin'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'kotlin'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "com.discord4j:discord4j-core:3.1.0"
implementation "com.natpryce:konfig:1.6.10.0"
implementation "org.json:json:20200518"
implementation "ch.qos.logback:logback-classic:1.2.3"
implementation "org.slf4j:slf4j-api:1.7.30"
}
shadowJar {
archiveBaseName.set('DreamBot')
archiveClassifier.set('')
archiveVersion.set('0.0.0')
mergeServiceFiles()
manifest {
attributes 'Main-Class': 'com.bancarelvalentin.dreambot.Main'
}
}
我无法确定确切的问题是我的Java安装无法正常运行,还是我的jar缺少东西?
感谢您的帮助!
解决方法
您的运行时Java版本低于编译时Java版本
Optional.isEmpty()来自JDK 11+,而不是JDK 8,9
build.gradle很好。
只需在JDK 11上运行