如何修复LinkageError发生在加载主类错误?使用其他JDK运行时?



我想在IntelliJ中启动一个Java ChatServer (Gradle JVM设置为Java 16.0.1应该是!)。运行类后,我得到以下错误:

Error: LinkageError occurred while loading main class edu.hm.cs.vt.chat.server.ChatServerStarter
java.lang.UnsupportedClassVersionError: edu/hm/cs/vt/chat/server/ChatServerStarter has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 55.0
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':chat:server:ChatServerStarter.main()'. Process 'command '/Users/username/opt/anaconda3/bin/java'' finished with non-zero exit value 1

我的本地配置设置如下:

Java版本:

java -version
openjdk version "11.0.6" 2020-01-14
which java
/Users/username/opt/anaconda3/bin/java

我的Java版本似乎是从conda使用的。

机器上安装的Java版本:

/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
16.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 16.0.1" /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home
1.8.241.07 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home

JAVA_HOME路径:

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home

为什么

'/Users/username/opt/anaconda3/bin/java'

出现在错误信息中??

我如何配置它使用16.0.1 JDK或者我做错了什么?

有三种方法,

首先是gradle。需要添加的属性

org.gradle.java.home=/path/to/jdk/directory

第二种方法是一次性测试像这样的终端

gradle build -Dorg.gradle.java.home=/JDK_PATH

添加build.gradle

路径的第三种方式
compileJava.options.fork = true
compileJava.options.forkOptions.executable = '/path_to_javac'

相关内容

  • 没有找到相关文章

最新更新