wsl 或者window terminal 下出现Java 14 switch expressions unrecognized解决方法:升级java jdk到14 or later
java 17更新安装wsl2:ubuntu
·
缘由
IDEA中build成功,但是automated build失败
$ ./gradlew
> Task :compileJava FAILED
Wordle/src/game/ui/WordleFrame.java:60: error: illegal start of expression
var background = switch (tallyResultOfOneLetter) {
^
Wordle/src/game/ui/WordleFrame.java:61: error: : expected
case EXACT -> COLOR_OF_EXACT;
^
Wordle/src/game/ui/WordleFrame.java:62: error: : expected
case MATCH -> COLOR_OF_MATCH;
^
Wordle/src/game/ui/WordleFrame.java:63: error: : expected
case NO_MATCH -> COLOR_OF_NO_MATCH;
^
4 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
2 actionable tasks: 2 executed
解决方法
后来发现IDEA中用的java JDK是17,而wsl中automated build用的是JDK 11,还没达到JDK14,所以无法识别14的表达式。
那就在wsl中升级JDK即可。
这里升级到Java17.
具体操作过程:wsl2下Ubuntu 20
首先输入
sudo apt update
如果ubuntu命令行出现 wsl ubuntu update显示err: 404 Not Found解决方法,请点击并且处理完之后再回到本文。
具体升级过程:
第一步:
sudo add-apt-repository ppa:linuxuprising/java
第二步:
sudo apt-get update
sudo apt-get install oracle-java17-installer oracle-java17-set-default
结果如下:
$ sudo apt-get install oracle-java17-installer oracle-java17-set-default
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
gsfonts gsfonts-x11 libxfont1 xfonts-encodings xfonts-utils
Suggested packages:
binfmt-support visualvm ttf-baekmuk | ttf-unfonts | ttf-unfonts-core ttf-kochi-gothic | ttf-sazanami-gothic
ttf-kochi-mincho | ttf-sazanami-mincho ttf-arphic-uming firefox | firefox-2 | iceweasel | mozilla-firefox
| iceape-browser | mozilla-browser | epiphany-gecko | epiphany-webkit | epiphany-browser | galeon | midbrowser
| moblin-web-browser | xulrunner | xulrunner-1.9 | konqueror | chromium-browser | midori | google-chrome
The following NEW packages will be installed:
gsfonts gsfonts-x11 libxfont1 oracle-java17-installer oracle-java17-set-default xfonts-encodings xfonts-utils
0 upgraded, 7 newly installed, 0 to remove and 1 not upgraded.
Need to get 4158 kB of archives.
After this operation, 6408 kB of additional disk space will be used.
Do you want to continue? [Y/n]
出现的条款,pagedown键划到底下,用上下左右键选择下方的ok
然后按方向键选择yes,按enter回车。
然后就是开始下载
安装完成之后
azheng@lishizheng:/mnt/e/shizheng_coding/software_design_venkat$ java --version
java 17.0.1 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
参考
[1]https://github.com/google/google-java-format/issues/535
[2]https://www.debugpoint.com/2021/09/install-java-17-ubuntu-mint/
更多推荐
已为社区贡献12条内容
所有评论(0)