Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Class to get information about running JavaFX applications on the current machine
package com.dustinredmond;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import java.io.IOException;
import java.util.List;
public class RunningJavaFXExample {
public static void main(String[] args) {
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor vm : vms) {
VirtualMachine attachedVm = null;
try {
attachedVm = VirtualMachine.attach(vm.id());
// if not a JavaFX application, continue
if (!attachedVm.getSystemProperties().containsKey("javafx.runtime.version")) {
continue;
}
System.out.println("-----------------------------");
System.out.printf("Display Name: %s\n", vm.displayName());
System.out.printf("ID: %s\n", vm.id());
System.out.printf("Provider: %s\n", vm.provider().name());
System.out.printf("Type:: %s\n", vm.provider().type());
System.out.println("- Agent Properties");
attachedVm.getAgentProperties().forEach((k, v) -> {
System.out.printf("\t%s\t-\t%s\n", k, v);
});
System.out.println("- System Properties");
attachedVm.getSystemProperties().forEach((k, v) -> {
System.out.printf("\t%s\t-\t%s\n", k, v);
});
System.out.println("-----------------------------\n");
} catch (AttachNotSupportedException | IOException ignored) {
} finally {
if (attachedVm != null) {
try {
attachedVm.detach();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment