我正在打包我的应用程序的影子 jar 。该应用程序使用 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 运行
关于java - Shadow jar 缺少常见的 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64690802/