mardi 11 avril 2023

How to solve java.lang.reflect.InaccessibleObjectException in a maven spring project?

I wanted to update a spring application built with maven from java 8 to java 17 but because of the Java Platform Module System, I got the following exception: Unable to make field private byte[] javax.crypto.spec.SecretKeySpec.key accessible: module java.base does not "opens javax.crypto.spec" to unnamed module @234523ab.

As I read in previous posts, I tried to open the package javax.crypto.spec to all unnamed modules by adding the following plugin to my pom.xml file:

<plugin> 
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>@{argLine}
      --add-opens java.base/javax.crypto.spec=ALL-UNNAMED
    </argLine>
  </configuration>
</plugin>

However, I still get the same exception. Does anyone know how to fix this problem within a maven spring application? Also, I read that --add-opens should only be used as a work-around, so does anyone knows a better solution?





Aucun commentaire:

Enregistrer un commentaire