Home > Back-end >  Springboot LaunchedURLClassLoader loading problem.
Springboot LaunchedURLClassLoader loading problem.

Time:11-27



Recently made a dynamic loading external jar package, the final use of class loaders is sun misc. The Launcher $AppClassLoader, some of these classes depend on the class already exists in the engineering, using the LaunchedURLClassLoader,

Both loader is a subclass of URLClassLoader, the problem is that external jar need class cannot be obtained from the LaunchedURLClassLoader obviously, has been an error "Java. Lang. ClassNotFoundException", the normal operation in the ide, use sun. Misc. The Launcher $AppClassLoader,

Is there any way to specify the class loader for LaunchedURLClassLoader? This is springboot jar package, does not exist project

CodePudding user response:

Grope for out, don't use the default this when loading external jar, because the current running class is using LaunchedURLClassLoader, so directly through the current class for this, then it is ok to use it to load external jar,

CodePudding user response:

Sun. Misc. The Launcher $AppClassLoader load path is "Java.class. Path", according to the parents to delegate mechanism, LaunchedURLClassLoader for its subclasses, should be in the class. The path to find the corresponding class,
Here's the problem, "Java.class. The path for the application path running environment, traditional applications are jre environment and application path, but springboot jar path,
Sun. Misc. The Launcher $AppClassLoader obviously won't load in the jar jar package, namely the lib springboot application package the following jar are done by its custom LaunchedURLClassLoader loaded, so that in the use of AppClassLoader to load the external class, which is with the class under the lib, it is unable to find a lower class, in this is Java. Lang. ClassNotFoundException "

CodePudding user response:

reference 1/f, dance response:
grope out, do not use the default this when loading external jar, because the current running class is using LaunchedURLClassLoader, so directly through the current class for this, then it is ok to use it to load external jar,

Specific what to do, the current class to obtain this is appclassloader ah, how to obtain LaunchedURLClassLoader to load the jar
  • Related