Sto cercando di ottenere un elenco di tutte le macchine virtuali in esecuzione sul mio computer utilizzando l'API Allega.Risolto il problema: java.lang.UnsatisfiedLinkError: nessun collegamento in java.library.path
Questo è il codice che sto usando:
import java.lang.reflect.Field;
import java.util.List;
import com.sun.tools.attach.*;
public class JVMListManager
{
static String pathToAdd = "C:/Program Files/Java/jdk1.7.0_03/jre/bin/attach.dll";
public static void setLibraryPath(String path) throws Exception {
System.setProperty("java.library.path", pathToAdd);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
}
private void listActiveVM()
{
List<VirtualMachineDescriptor> vm = VirtualMachine.list();
int i= 1;
for(VirtualMachineDescriptor vmD : vm)
{
System.out.println(i + ". " + vmD.displayName());
i++;
}
}
public static void main(String[] args) throws Exception
{
setLibraryPath(pathToAdd);
JVMListManager jvmListManager = new JVMListManager();
jvmListManager.listActiveVM();
}
}
ERRORE:
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
Per favore fatemi sapere quali metodi posso usare per risolvere questo problema.
Ho anche provato a utilizzare System.load (pathToAdd); Anche io ho fatto riferimento a questo Blog post, ma non funziona. : '(
Vedere http://stackoverflow.com/questions/5565356/java-attach-api-changing-java-library-path-dynamically –
il pathToAdd punta direttamente alla dll, dovrebbe puntare invece alla cartella contenente la dll . –