I'm upgrading java version in our production code from java 8 to java 11.
I have to add the below JDK module configuration in the application java start command due to usage of third party libraries like flume, zookeeper etc.
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
After adding this configuration and java application is starting fine.
But when I run the tests using mvn test
the tests are failing. I've added the below configuration to the maven-surefire-plugin but still it is throwing error.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>--illegal-access=permit</argLine>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
<argLine>--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED</argLine>
<argLine>-Dillegal-access=permit</argLine>
</configuration>
</plugin>
I think I'm not passing the argument correctly in the maven test. Any idea what I'm doing wrong and how to fix this?
--add-opens Some libraries do deep reflection, meaning setAccessible(true) , so they can access all members, including private ones. You can grant this access using the --add-opens option on the java command line. No warning messages are generated as a result of using this option.
2.1. The Maven compiler accepts this command with –target and –source versions. If we want to use the Java 8 language features, the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the –target value should be 1.8. The default value for both of them is the 1.6 version.
Maven compiles the source code file (s) and then tests the source code file (s). Then Maven runs the test cases. Finally, Maven creates the package. Now open the command console, go the C:\MVN\consumerBanking arget\classes directory and execute the following java command. Hello World! Let's see how we can add additional Java files in our project.
By default, Maven adds a source file App.java and a test file AppTest.java in its default directory structure, as discussed in the previous chapter. Let's open the command console, go the C:\MVN\consumerBanking directory and execute the following mvn command. Maven will start building the project. [INFO] Scanning for projects...
By default, Maven adds a source file App.java and a test file AppTest.java in its default directory structure, as discussed in the previous chapter. Let's open the command console, go the C:\MVN\consumerBanking directory and execute the following mvn command.
Until Java 8, we used the version number as 1. x where x represents Java's version, like 1.8 for Java 8. For Java 9 and above, we can just use the version number directly: Similarly, we can define the version using properties as: Maven added its support for Java 9 in 3.5.0, so we'll need at least that version.
It is a single argLine
, like:
<argLine>
--add-exports org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED
--add-exports org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED
</argLine>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With