0

I am getting an error when I try to run the integration test (@SpringBootTest) in my application. I got a solution to use below the Java option

--add-opens java.base/java.nio=ALL-UNNAMED

I have checked it by editing the run configuration and it is working completely. (Run test case with above argument)

But I want to add through the pom file so when I run mvn clean install then it should work. I have tried this but it didn't work.

     <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
                <jvmArguments>
                    --add-opens java.base/java.nio=ALL-UNNAMED
                </jvmArguments>
            </configuration>
      </plugin>

I have also checked -Djava.base/java.nio=ALL-UNNAMED It is also not working. What is the right way to use this JVM argument so it can set runtime?

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
Chetan
  • 63
  • 1
  • 8
  • What exactly was the error you got: `I am getting an error when I try to run the integration test`??? It would also help to get the exact spring boot version, JDK version etc. you are using? – khmarbaise Jul 11 '23 at 17:08
  • @khmarbaise I am using ignite-core maven dependency in pom and it works well til Java 8. But now I want to use Java 17 and ignite-core does not work with the above Java 8 version directly. We need to add JVM arguments in Java option https://www.appsloveworld.com/java/100/360/how-to-fix-could-not-initialize-class-org-apache-ignite-ignitejdbcthindriver-er https://apacheignite.readme.io/docs/getting-started#running-ignite-with-java-11-and-later-versions – Chetan Jul 12 '23 at 05:47
  • @khmarbaise I am getting below error while run springboot test with java 17 Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.ignite.IgniteJdbcThinDriver – Chetan Jul 12 '23 at 05:53

1 Answers1

1

spring-boot-maven-plugin doesn't run your tests. It's Maven's Surefire plugin that does that. You need to configure its argLine property:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>--add-opens java.base/java.nio=ALL-UNNAMED</argLine>
  </configuration>
</plugin>
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242