Java Attach API可以连接到本地虚拟机并加载代理。如何连接到另一台计算机上的VM以加载代理程序?
我知道JMX。但是我不知道如何将我的自定义代理加载到远程VM。
也许存在其他方法来解决我的问题(加载和执行自定义代码(代理)到远程VM) ?
乌利希期刊指南。我想在远程JVM上执行自定义代码。初始JVM参数的独立性是加分项。
谢谢。
在生产环境中运行应用程序服务器(Tomcat)是没有问题的,即使附带了远程调试。
更新如果你想在你的应用程序中执行自定义代码,那么一个解决方案是编写一个类并编译它,将其存储在服务器上,然后在你的应用程序中执行一些方法,如:
/**
* This method:
* <li>loads a class from the server file system
* <li>does a lookup for the method to execute
* <li>creates a new instance of the specified class
* <li>executes the given method with the given arguments
* (which can be null if the method doesn't have arguments)
* <li>returns the result of the invoked method
*
* @param classUrlOnTheServer
* @param className
* @param methodNameToExecute
* @param argumentsForTheMethod arguments that should be passed to
* the method of the loaded class - can
* be null.
* @return returns the result of the invoked method
* @throws ClassNotFoundException
* @throws MalformedURLException
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
public static Object loadAndExecuteCustomMethodFromALoadedClass(String classUrlOnTheServer,
String className,
String methodNameToExecute,
Object ... argumentsForTheMethod)
throws ClassNotFoundException,
MalformedURLException,
SecurityException,
NoSuchMethodException,
InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
File file = new File(classUrlOnTheServer);
URL url = file.toURI().toURL();
URL[] urls = new URL[] { url };
ClassLoader cl = new URLClassLoader(urls);
Class clazz = cl.loadClass(className);
Method method = clazz.getDeclaredMethod(methodNameToExecute);
Object instance = clazz.newInstance();
Object result = method.invoke(instance, argumentsForTheMethod);
return result;
}
我不明白这个问题,你只是想连接到远程虚拟机吗?连接后,您可以执行任何您想要的,事件终止虚拟机。你必须在调试模式下启动你的VM:
- xdebug -Xrunjdwp:运输= dt_socket地址= 8000,server = y,暂停= n
然后在Eclipse中创建一个新的远程应用程序概要文件。看看这个:http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html
我找到了实验性的解决方案:jsadebugd。
然后可以通过sun.jvm.hotspot.jdi附加到它。SAPIDAttachingConnector 连接器。