我已经在网上读了很多类似的帖子,但似乎找不到解决办法。我希望能够在 Java 版本之间切换。提前谢谢!操作系统:Ubuntu 16.04.6 LTS x86_64
我已经手动安装并设置了 update-alternatives java 和 javac
sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-12-oracle/bin/java 1091 auto mode
* 1 /usr/lib/jvm/java-12-oracle/bin/java 1091 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/java 0 manual mode
sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-12-oracle/bin/javac 1091 auto mode
* 1 /usr/lib/jvm/java-12-oracle/bin/javac 1091 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 0 manual mode
echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64
PATH 显示 /usr/lib/jvm/java-8-openjdk-amd64/bin 和 /usr/lib/jvm/java-12-oracle/bin
echo $PATH
/home/myname/Repositories/build/depot_tools:/home/myname/bin:/home/myname/.local/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda/bin:/snap/bin:/usr/lib/jvm/java-12-oracle/bin:/usr/lib/jvm/java-12-oracle/db/bin
此外,我无法更改 JAVA_HOME。我不知道它设置在哪里我没有在任何地方设置 JAVA_HOME,我检查了 /etc/environment 、 ~/.bashrc 和 ~/.profile
好的,更新,关于 JAVA_HOME。我找到了它的设置位置(etc/profile),然后我取消了它的设置并进行了源化。不确定它是如何在那里设置的,也许是一个程序做的。
我想要和期望的是在 Java 版本之间切换并且能够编译和执行 Java 程序。
例如,当我从终端运行更高版本的 Java 程序时。
线程“main”中的异常 java.lang.UnsupportedClassVersionError: 程序已由较新版本的 Java Runtime(类文件版本 54.0)编译,此版本的 Java Runtime 仅识别最高 52.0 的类文件版本
最后,对于 update-java-alternatives --list,我有:
update-java-alternatives --list
java-12-oracle 1091 /usr/lib/jvm/java-12-oracle
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
此外如果我尝试设置它:
sudo update-java-alternatives -s java-12-oracle
update-alternatives: error: no alternatives for jaccessinspector
update-alternatives: error: no alternatives for jaccesswalker
update-alternatives: error: no alternatives for kinit
update-alternatives: error: no alternatives for klist
update-alternatives: error: no alternatives for ktab
update-alternatives: error: no alternatives for mozilla-javaplugin.so
update-java-alternatives: jdk alternative does not exist: /usr/lib/jvm/java-12-oracle/bin/jaccessinspector
update-java-alternatives: jdk alternative does not exist: /usr/lib/jvm/java-12-oracle/bin/jaccesswalker
update-java-alternatives: jdk alternative does not exist: /usr/lib/jvm/java-12-oracle/bin/kinit
update-java-alternatives: jdk alternative does not exist: /usr/lib/jvm/java-12-oracle/bin/klist
update-java-alternatives: jdk alternative does not exist: /usr/lib/jvm/java-12-oracle/bin/ktab