Java Attach API可以连接到本地VM并将代理装载到它。如何连接到另一台计算机上的VM以加载代理?连接到远程(非本地)VM
我知道JMX。但我没有发现如何将我的自定义代理加载到远程VM。
也许存在另一种方法来解决我的问题(加载和执行自定义代码(代理)到远程虚拟机)?
upd。我想在远程JVM上执行自定义代码。初始JVM参数的独立性是正的。
谢谢。
Java Attach API可以连接到本地VM并将代理装载到它。如何连接到另一台计算机上的VM以加载代理?连接到远程(非本地)VM
我知道JMX。但我没有发现如何将我的自定义代理加载到远程VM。
也许存在另一种方法来解决我的问题(加载和执行自定义代码(代理)到远程虚拟机)?
upd。我想在远程JVM上执行自定义代码。初始JVM参数的独立性是正的。
谢谢。
我发现实验方案:jsadebugd。
然后您可以通过连接到sun.jvm.hotspot.jdi.SAPIDAttachingConnector连接器。
你是什么意思?多少步骤? –
你在程序中解决了这个问题吗? @Andrew Knodratovich –
我和你有同样的问题。如何使用程序连接远程jvm并注入代码而无需重新启动远程jvm来添加一些调试参数? –
我不明白这个问题,你只是想连接到远程虚拟机?当连接时,你可以执行任何你想要的,事件终止虚拟机。 你必须要对你的虚拟机在调试模式:
-Xdebug -Xrunjdwp:交通= dt_socket,地址= 8000,服务器= Y,暂停= N
然后在Eclipse例如,创建一个新的远程应用程序个人资料。检查此: http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html
我知道调试接口,但我需要这个用于生产,而不是调试。 –
在生产中运行应用程序服务器(Tomcat),即使使用remote debugging attached也没有问题。
UPDATE
如果要执行你的应用程序中的自定义代码,则一个解决办法是写一个类和编译它,在一些地方保存在服务器上,然后你的应用程序中执行一些方法,这样:
/**
* 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;
}
我需要注入自定义代码。使用JMX,我可以获得有关远程JVM的信息,但我无法注入并执行代码。 Attach API提供了在JVM中加载可执行代理的方法,但只提供本地JVM。我正在寻找与远程JVM一样的方法。 –
通过远程调试,您可以评估表达式(整行代码)。您不能保存该代码,但可以更改字段和变量的值。我不完全明白你想要什么,你可以编辑你最初的问题,并详细解释。 – davorp
如您所愿更新。 –
您需要用这种方法解决什么是原始问题? –
远程运行干净JVM的附件,监控和代码更新 –
我强烈建议不要使用代理来更新软件。试想一下你可以得到的支持问题。 –