问题描述
我使用基于 microsoft/nanoserver
(实际上基于 the jenkins slave image)的 windows Docker 容器。 jstack
无法在此容器中工作,如下所示:
C:\>jstack 39624
java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider Could not be instantiated
39624: no providers installed
The -F option can be used when the target process is not responding
Oracle、OpenJDK 和 Zulu 8 会发生这种情况。
解决方法
docker 容器丢失了 c:\windows\system32\advapi32.dll
。从构建主机复制它后,一切正常。
在对 Dependencies 进行一些调查后,这是缺失的部分。我尝试过的每个 JDK 都有一个 jre\bin\attach.dll
,大概是由 WindowsAttachProvider 中的代码加载的:
// native functions in this library
static {
System.loadLibrary("attach");
}
因此在依赖项中加载 attach.dll
给了我可能的罪魁祸首: