1
0

More than 1 year has passed since last update.

java.lang.IllegalStateException: Unable to load cache itemエラーが発生する

Last updated at Posted at 2023-02-11

はじめに

Javaのテストツールを導入しようとした際に発生したエラーです

問題

mvn testをしたところ以下のエラーが発生しました

watanabejin@watanabejin-Latitude-3520:~/workspace/gauge-e2e$ mvn test
[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
[ERROR] Caused by: Exception com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @49c43f4e [in thread "main"]

解決方法

JAVA_HOMEを設定したところ治りました

$ 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-11-openjdk-amd64/bin/java   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
* 2            /usr/lib/jvm/java-11-oracle/bin/java          1091      manual mode

$ sudo vi /etc/environment

以下を追加して保存(値は各自の環境に合わせてください)

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
$ source /etc/environment
$ echo $JAVA_HOME

おわりに

Javaほとんどやったことがないので環境依存のエラーにたくさん遭遇します
コンテナ化できないのが毎度悩ましいです

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0