更新时间:2022-06-05 17:50:58
从此文档中
http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/invocation.html
当一个线程附加到VM时,上下文类加载器就是引导加载程序。
"When a thread is attached to the VM, the context class loader is the bootstrap loader."
通过AttachCurrentThread连接到JVM的任何本机线程()只获取引导类加载器,甚至不获取系统类加载器。除非您明确修复新线程的上下文类加载器,否则ServiceLoader引用的类将不可用。
Any native thread attached to the JVM via AttachCurrentThread() gets only the bootstrap class loader, not even the system class loader. Classes referenced by ServiceLoader will not be available unless you explicitly fix up the new thread's context class loader.
这可以这样做:
java.lang.Thread.currentThread().setContextClassLoader(
java.lang.ClassLoader.getSystemClassLoader()
);