Я хочу внедрить бегущее Java-Swing-application на моем компьютере для автоматизации ввода.import com.sun.tools.attach.VirtualMachine;
public class AttachAgent {
public static void main(String[] args) throws Exception {
// Replace with real PID of the running Swing app
String pid = "16740";
// Replace with the full path to your built SwingAgent JAR
String agentPath = "C:\\Temp\\SwingHacker.jar";
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent(agentPath);
vm.detach();
System.out.println("Agent attached!");
}
}
Это содержание моего swinghacker.jar :
SwingHacker.jar
├─ META-INF
│ ├─ MANIFEST.MF
├─ SwingAgent.class
< /code>
Это manifest.mf: < /p>
Manifest-Version: 1.0
Agent-Class: SwingAgent
Can-Redefine-Classes: true
Permissions: all-permissions
И это Swingagent :
import java.awt.Component;
import java.awt.Container;
import java.awt.Window;
import java.lang.instrument.Instrumentation;
import javax.swing.JButton;
public class SwingAgent {
public static void agentmain(String agentArgs, Instrumentation inst) {
System.out.println("Agent attached!");
try {
Thread.sleep(2000L);
} catch (Exception var6) {
}
for(Window window : Window.getWindows()) {
clickButtonByText(window, "Login");
}
}
private static boolean clickButtonByText(Component comp, String text) {
if (comp instanceof JButton && text.equals(((JButton)comp).getText())) {
System.out.println("Clicking button: " + text);
((JButton)comp).doClick();
return true;
} else {
if (comp instanceof Container) {
for(Component child : ((Container)comp).getComponents()) {
if (clickButtonByText(child, text)) {
return true;
}
}
}
return false;
}
}
}
< /code>
Когда я запускаю это, я получаю эту ошибку: < /p>
Exception in thread "main" com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:169)
at jdk.attach/com.sun.tools.attach.VirtualMachine.loadAgent(VirtualMachine.java:538)
at AttachAgent.main(AttachAgent.java:13)
Что случилось или как это исправить?import java.io.FileWriter;
import java.io.PrintWriter;
public class SwingAgent {
public static void agentmain(String agentArgs, java.lang.instrument.Instrumentation inst) {
try (PrintWriter out = new PrintWriter(new FileWriter("C:\\Temp\\swinghacker_log.txt", true))) {
out.println("HELLO FROM AGENT!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... iled-to-in
Введите управляемое Java-Swing-применение: агент JAR загружен, но агент не смог инициализировать ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Получение предупреждения «Java-агент загружен» в intelliJ после обновления JDK с 17 по 21.
Anonymous » » в форуме JAVA - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Получение предупреждения «Java-агент загружен» в intelliJ после обновления JDK с 17 по 21.
Anonymous » » в форуме JAVA - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-