I\'m using com.sun.tools.attach
from jdk\'s tools.jar
and it need an specified java.library.path
env pointing to attach.dll
a
The API you are using is using loadLibrary(String). It seems you cannot successfully pre-empt (cause it to succeed) this by invoking the more explicit load(String) first.
So you must to specify the path in java.library.path
.
That System property is set once early in JVM lifecycle and is not modifiable by standard means.
So the conventional solution will be to pass an appropriate java.library.path
when you launch the JVM.
Alternatively, you could look into the hacks to change this property after JVM startup using reflection. I have not tried any of these.
For example, see here:
System.setProperty( "java.library.path", "/path/to/libs" );
Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
BTW, I would recommend pre-pending your custom path to the existing path, rather than replacing it.