When compiling a project, Maven throws an error

OS Linux - Ubuntu 20.04.2 LTS When compiling a project, Maven throws an error

[ERROR] Error executing Maven.
[ERROR] java.lang.IllegalStateException: Unable to load cache item
[ERROR] Caused by: Unable to load cache item
[ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper

java -version

openjdk version "17" 2021-09-14 LTS
OpenJDK Runtime Environment (build 17+35-LTS)
OpenJDK 64-Bit Server VM (build 17+35-LTS, mixed mode, sharing)

mvn -version

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17, vendor: BellSoft, runtime: /usr/lib/jvm/bellsoft-java17-amd64
Default locale: ru_RU, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-37-generic", arch: "amd64", family: "unix"

java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'

java.home = /usr/lib/jvm/bellsoft-java17-amd64
1

3 Answers

Same issue i also faced.And i got the solution. Update latest maven version which is 3.8.3. With latest maven it is working.

mvn -vApache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)Maven home: /opt/maven
Java version: 17, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.10.0-1051-oem", arch: "amd64", family: "unix"
0

I faced the same issue. Sadly I just could update to 3.6.3 via the package manager so I installed it manually. Steps to install on ubuntu below:

Maven 3.3+ requires JDK 1.7 or above to be installed.

Download Apache Maven. I installed 3.8.4, you can check for the newest version here:

We save the archive to /tmp

$ TMP_MAVEN_VERSION=3.8.4
$ wget -P /tmp

Then unzip it to /opt and remove the archive

$ sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
$ sudo rm /tmp/apache-maven-*-bin.tar.gz

Next we create a sym-link

$ sudo ln -s /opt/apache-maven-$TMP_MAVEN_VERSION /opt/maven

Lastly we set up the env

$ sudo echo "export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}" >> /etc/profile.d/maven.sh

To use it without restarting we make it executable and run in

$ sudo chmod +x /etc/profile.d/maven.shsource /etc/profile.d/maven.sh
$ source /etc/profile.d/maven.sh

Now you can verify that it is properly installed

$ mvn -v
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /opt/maven
Java version: 11.0.13, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-1022-aws", arch: "amd64", family: "unix"

derived by

As of 2021/10/25, maven is not supporting Java 17.

Create vi ~/.mavenrc file and give any version lower than 17.

export JAVA_HOME=/usr/lib/jvm/java-16-openjdk-amd64/

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like