I am trying to create Dynamic classes in Java 17 spring boot application using Javasssist library and this works only when we add VM option as –add-opens java.base/java.lang=ALL-UNNAMED in the spring boot Run Config. If this VM option is not added we get error
unable to make protected final java.lang.class java.lang.classloader.defineclass security protection domain throws java.langClassformaterror accessible: module java.base does not openns java.lang to unnamed module
Now when we want to deploy our application, we need some alternative to –add-opens java.base/java.lang=ALL-UNNAMED added in the code say pom.xml or some other file as we don’t want to use VM options. But none of the options added in pom.xml seem to work. We always get the same error.
Have tried to add many POM build plugins like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
or
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<jvmArguments>--add-opens java.base/java.lang=ALL-UNNAMED</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
but nothing worked. Can someone help how we can solve this error codewise as an alternative to VM option.