commit 322a89dc51a0368797b0964c7ea5d27c0147e012 Author: Lixfel Date: Tue Oct 12 16:14:06 2021 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f419dc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea +/target diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0846d5f --- /dev/null +++ b/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + de.steamwar + AttachTool + 1.0 + + + UTF-8 + 16 + 16 + + + + + + org.apache.maven.plugins + 3.2.0 + maven-jar-plugin + + + + true + de.steamwar.AttachTool + + + + + + + \ No newline at end of file diff --git a/src/main/java/de/steamwar/AttachTool.java b/src/main/java/de/steamwar/AttachTool.java new file mode 100644 index 0000000..6c67a87 --- /dev/null +++ b/src/main/java/de/steamwar/AttachTool.java @@ -0,0 +1,39 @@ +package de.steamwar; + +import com.sun.tools.attach.AttachNotSupportedException; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; +import com.sun.tools.attach.spi.AttachProvider; + +import java.io.IOException; +import java.util.Properties; + +public class AttachTool { + + public static void main(String[] args) { + if(args.length == 0) { + for(AttachProvider provider : AttachProvider.providers()) { + for(VirtualMachineDescriptor vmd : provider.listVirtualMachines()) { + System.out.println(vmd.id() + " " + vmd.displayName()); + } + } + }else if(args.length == 1) { + try { + VirtualMachine vm = VirtualMachine.attach(args[0]); + + // start management agent + Properties props = new Properties(); + props.put("com.sun.management.jmxremote.port", "1999"); + props.put("com.sun.management.jmxremote.authenticate", "false"); + props.put("com.sun.management.jmxremote.ssl", "false"); + vm.startManagementAgent(props); + + vm.detach(); + } catch (AttachNotSupportedException | IOException e) { + e.printStackTrace(); + return; + } + + } + } +}