В системе настройки сделаны для java 11. В путях linux указана java 11. Нужно настроить maven проект на java 17.
$ java -version
openjdk version "11.0.18" 2023-01-17
Нужна java 17, для этого нужно установить JAVA_HOME.
В .bashrc добавить строку
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Проверка:
$ echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
$ /usr/lib/jvm/java-17-openjdk-amd64/bin/java -version
openjdk version "17.0.6" 2023-01-17
~/prog/java/s253/gs-spring-boot/complete$ ./mvnw -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/vasi/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 17.0.6, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
~/prog/java/s253/gs-spring-boot/complete$ ./mvnw clean package
.......... см. ниже в логе (using Java 17.0.6 on vasi-note with PID 11618)
:: Spring Boot :: (v2.5.3)
2023-04-29 17:26:02.184 INFO 11618 --- [ main] c.e.springboot.HelloControllerTest :
Starting HelloControllerTest using Java 17.0.6 on vasi-note with PID 11618 (started by vasi in /home/vasi/prog/java/s253/gs-spring-boot/complete)
..........
ХОТЯ! в pom.xml указано properties - java.version = 11. И
$ java -version
openjdk version "11.0.18" 2023-01-17
Maven использует в своем скрипте JAVA_HOME! Куда указывает $PATH на бинарник java не имеет значения.
JAVA_HOME должна указывать на папку, содежащую bin/, lib/ и т.п.
$ echo $JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64 $ echo $PATH .../opt/maven/bin:/usr/lib/jvm/java-16-oracle/bin:/usr/lib/jvm/java-16-oracle/db/bin... $ mvn -version Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: /opt/maven Java version: 17.0.7, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: ru_RU, platform encoding: UTF-8 OS name: "linux", version: "5.4.0-150-generic", arch: "amd64", family: "unix" $ gradle -version ------------------------------------------------------------ Gradle 6.7 ------------------------------------------------------------ Build time: 2020-10-14 16:13:12 UTC Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3 Kotlin: 1.3.72 Groovy: 2.5.12 Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020 JVM: 17.0.7 (Private Build 17.0.7+7-Ubuntu-0ubuntu118.04) OS: Linux 5.4.0-150-generic amd64
Добавить в .bashrc
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Можно таким способом, средствами ОС, через link (ln -s ...) на каталог java:
$ echo $JAVA_HOME /usr/local/sdkman/candidates/java/currents
KOTLIN тоже использует JAVA_HOME
Windows
($ - promt command line)
В cmd:
$ set JAVA_HOME=c:\po\java11 $ echo %JAVA_HOME% c:\po\java11
В PowerShell:
// установить переменную $ [Environment]::SetEnvironmentVariable("JAVA_HOME","c:\po\java11") // проверить переменную $ $env:JAVA_HOME c:\po\java11
Java Class File Versions (https://howtodoinjava.com/java/exception-handling/class-file-has-wrong-version/):
Java Version | Class File Version |
---|---|
Java 8 | 52.0 |
Java 9 | 53.0 |
Java 10 | 54.0 |
Java 11 | 55.0 |
Java 12 | 56.0 |
Java 13 | 57.0 |
Java 14 | 58.0 |
Java 15 | 59.0 |
Java 16 | 60.0 |
Java 17 | 61.0 |
Java 18 | 62.0 |
Java 19 | 63.0 |
Java 20 | 64.0 |
Java 21 | 65.0 |
Java 22 | 66.0 |
Java 23 | 67.0 |
Java 24 | 68.0 |
Установка версии Java в Linux с update-alternatives:
$ 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-17-openjdk-amd64/bin/java 1711 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode Press to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode
В Linux, после установки JAVA_HOME, нужно перезайти в shell.