Thursday, July 11, 2019

java.security.NoSuchAlgorithmException

Exceptions with
java.security.NoSuchAlgorithmException: ... not available
in the stacktrace may be caused by overriding the system property java.ext.dirs. Setting java.ext.dirs has been a popular but dangerous way for adding all jars within a directory to the classpath. Java 9 finally removed the feature (https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-2C896CA8-927C-4381-A737-B1D81D964B7B). Versions before Java 9 used the extension directories to find essential jars like sunjce_provider.jar, which contains a lot of algorithms required for SSL/TLS for example. So if you set java.ext.dirs, you may experience exceptions as described above. Solutions: a) include %JRE_HOME%/lib/ext respectively $JRE_HOME/lib/ext into the list of directories you set and hope that the environment variable JRE_HOME is set correctly or b) (much better) use -classpath instead. java and javac accept wildcards in -classpath. JNI does not so you have to write some code to make the expansion yourself.