我正在使用com.sun.tools.attach
jdk ,它需要在启动时指向tools.jar
一个指定的env才能正确地设置提供程序,例如. 由于某些原因,我需要动态加载其中一个 bundled 。我尝试使用这样的一些:java.library.path
attach.dll
WindowsAttachProvider
attach.dll
public static void main(String[] args) throws Exception {
Path bin = Paths.get(System.getProperty("user.dir"),"bin").toAbsolutePath();
switch (System.getProperty("os.arch")) {
case "amd64":
bin = bin.resolve("win64");
break;
default:
bin = bin.resolve("win32");
}
// Dynamic setting of java.library.path only seems not sufficient
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + bin.toString());
// So I try to manual loading attach.dll. This is not sufficient too.
System.load(bin.resolve("attach.dll").toString());
// I'm using com.sun.tools.attach in my app
new myApp();
}
如果我用 jdk 运行它(在正常的 jre 中),它会向我报告:
java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider:
Provider sun.tools.attach.WindowsAttachProvider could not be instantiated:
java.lang.UnsatisfiedLinkError: no attach in java.library.path
Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException:
no providers installed
at com.sun.tools.attach.VirtualMachine.attach(...
如何安装附加提供程序而不指定在启动-Djava.library.path
时指向attach.dll
?