Java Attach APIは、ローカルVMに接続し、エージェントをエージェントにロードできます。エージェントを読み込むために別のコンピュータのVMにどのように接続できますか?
私はJMXについて知っています。しかし、私はどのように私のカスタムエージェントをリモートVMにロードするのか分からなかった。
たぶん私の問題を解決する別の方法が存在する(リモートVMにカスタムコード(エージェント)をロードして実行する)?
UP。リモートJVMでカスタムコードを実行したい初期JVMパラメータの独立性はプラスです。
ありがとう。
It's no problem running a application server (Tomcat) in production, even with remote debugging attached.
更新
あなたのアプリケーション内でカスタムコードを実行したい場合は、クラスを作成してコンパイルし、サーバのどこかに格納してから、アプリ内で次のようなメソッドを実行することができます:
/**
* This method:
* loads a class from the server file system
* does a lookup for the method to execute
* creates a new instance of the specified class
* executes the given method with the given arguments
* (which can be null if the method doesn't have arguments)
* 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に接続したいですか?接続すると、必要なものを実行できます。イベントはVMを終了します。 デバッグモードでVMを起動する必要があります:
-Xdebug -Xrunjdwp:transport = dt_socket、address = 8000、server = y、suspend = n
Then in Eclipse for example, create a new remote application profile. check this : http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html