简体   繁体   中英

HowTo Start/Stop Remote Java application

Spec: Jdk1.7,O/s:windows-server (5 -slave + 1 -master)

I have the following

  • 5 nos Win O/s systems with Jre already installed
  • Customized Java application deployed on all of the 5 systems.

Question : Remotely start/stop all of the Java applications ( sequentially ) from the Master windows server.

Note: - Need to use ANT tasks to fire the remote start/stop applications.

You could install SSH on the windows machines (if not already present) and on the master, write a function that for each of the slaves, SSH to them and start the java applications from command line. JSch is a popular Java SSH library.

String user="user";
String host="slave_n";
String command ="java -jar helloworld.jar";
JSch jsch=new JSch();  
Session session=jsch.getSession(user, host, 22);
session.connect();
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command);

code snippet taken from http://www.jcraft.com/jsch/examples/Exec.java.html there is a complete example in the link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM