This is intended to be a practical solution to disable specifically these types of logs in Java programs.
Please note that this solution requires a little bit of work.
As you can imagine, this warning is related to reflective operations called by our program or its dependencies.
Let’s assume that we are facing a warning like the following one:
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access using Lookup on org.neo4j.memory.RuntimeInternals (jar:file:/home/user/workspace/explore/target/explore-1.0-with-dependencies.jar!/BOOT-INF/lib/neo4j-unsafe-4.1.2.jar!/) to class java.lang.String WARNING: Please consider reporting this to the maintainers of org.neo4j.memory.RuntimeInternals WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
Take a look now to the class name at the end of the second line (highlighted in the red rectangle). In my case it’s java.lang.String
The next step is to find out the corresponding source module and package.
In this case the source module is java.base and the package is java.lang as you can see below:
We can now launch our program adding a specific JVM option:
In my case I’m going to add the following option:
java --add-opens=java.base/java.lang=ALL-UNNAMED -jar myapp.jar
After this you could have 2 different outputs:
- the logs are completely disappeared
- you are meeting another similar set of warnings
In the second case don’t worry and simply repeat the process above till you don’t see any other warning.
You can find more accurate information about reflection and JVM options at https://openjdk.java.net/jeps/261
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.