Created
February 18, 2021 20:16
-
-
Save dustinkredmond/4f2629c8ef4eac3857bfa453e61683ae to your computer and use it in GitHub Desktop.
Class to get information about running JavaFX applications on the current machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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