Using JRemoteRun
Start jmx agent of remote system by adding following following properties for jvm command line:
-Dcom.sun.management.jmxremote.port=7663 -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
Client code, which print Hello world in remote system:
import java.io.Serializable;
import java.net.*;
import java.util.*;
import net.sf.jremoterun.CodeForExecutingSupport;
import net.sf.jremoterun.RemoteRunner;
public class Client extends CodeForExecutingSupport {
public static void main(final String[] args) throws Exception {
final int jmxPort = 7663;
final Collection<URL> classpath = new LinkedHashSet();
final List<Serializable> params = new ArrayList();
final Serializable classloaderId = net.sf.jremoterun.SimpleFindParentClassLoader.defaultClassLoaderId;
final Serializable result = RemoteRunner.remoteRunOnLocalHost(
jmxPort, "user", "password", Client.class, classpath,
params, classloaderId);
if (result != null) {
System.out.println(result);
}
}
protected void methodSwitcher() throws Throwable {
runCode1Simple();
}
void runCode1Simple() throws Exception {
System.out.println("Hello World!..");
}
void runCode3ReturnResult() throws Exception {
System.out.println("In runCode2Simple " + new Date());
result = new Date();
}
}