java.lang.ClassNotFoundException Solutions

How to locate a class load path

Class is usually from .jarthe loaded file encountered ClassNotFoundExceptionwhen we may need to locate this class which module provides
Class#getProtectionDomain()can help us

fun main(args: Array<String>) {
        val c = Class.forName(args[0])
        println("${ c.getProtectionDomain() }")
}

For example javax.activation.DataHandler is deprecated in JDK 11 deleted, but it JavaMail need these classes, after the Maven repository https://mvnrepository.com/artifact/javax.activation/activation/1.1.1 jar file download

$ jk -cp activation-1.1.1.jar MainKt javax.activation.DataHandler
ProtectionDomain  (file:/home/xxx/kt/FindClass/activation-1.1.1.jar <no signer certificates>)
 jdk.internal.loader.ClassLoaders$AppClassLoader@1affbebc
 <no principals>
 java.security.Permissions@4a574795 (
 ("java.io.FilePermission" "/home/xxx/kt/FindClass/activation-1.1.1.jar" "read")
 ("java.lang.RuntimePermission" "exitVM")
)

From this we can know before production and development environments is exactly what is missing jar files, so as to solve the anomaly


Guess you like

Origin www.cnblogs.com/develon/p/11703486.html