13
0
Dieser Commit ist enthalten in:
Lixfel 2021-10-12 16:14:06 +02:00
Commit 322a89dc51
3 geänderte Dateien mit 75 neuen und 0 gelöschten Zeilen

2
.gitignore vendored Normale Datei
Datei anzeigen

@ -0,0 +1,2 @@
/.idea
/target

34
pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.steamwar</groupId>
<artifactId>AttachTool</artifactId>
<version>1.0</version>
<properties>
<file.encoding>UTF-8</file.encoding>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2.0</version>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>de.steamwar.AttachTool</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

Datei anzeigen

@ -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;
}
}
}
}