Problem with Surefire library
Recently one of my Jenkins build failed with an error Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter
. A surefire plugin that maven was using to run JUnit tests was failing.
A solution to fix the issue with Surefire library
I found two solutions to this problem. But first, let’s try to understand what exactly caused this problem.
In OpenJDK version 1.8.181, there were some behavioral changes that might be the reason for this issue. I had updated the Java version to use based on the system in my Jenkins build. This will make a system to get the latest open JDK. Also, there is a bug in the surefire plugin that is using absolute paths while Java will allow only relative paths. You can find more details about this issue here.
So to fix this issue, the easiest solution is Djdk.net.URLClassPath.disableClassPathURLCheck=true
.
Another solution that worked for me was to go back to the older JDK version that I was using in Jenkins build before I shifted to System
option. I went back to open JDK version 1.8.118 version and it did the trick also.
Conclusion
In conclusion, I showed how to fix an error during Jenkins build “Could not find or load main class”. If you enjoyed this post, subscribe to my blog here.
References
- Could not find forkedbooter class – here
- Surefire bug