在启动程序时,如果是tomcat ,只需要在startup.bat最前面加入下面一行:
set JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
如果是java程序,应该: java %JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n 你的程序。
Java使用SSH远程访问Windows并执行命令import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import ch.ethz.ssh2.Connection
import ch.ethz.ssh2.Session
import ch.ethz.ssh2.StreamGobbler
public class SSHWindows {
public static void main(String[] args) {
// TODO Auto-generated method stub
String hostname ="192.168.30.10"
String username="administrator"
String password="Talent123"
try{
//建立连接
Connection conn= new Connection(hostname)
// System.out.println("set up connections")
conn.connect()
//利用用户名和密码进行授权
boolean isAuthenticated = conn.authenticateWithPassword(username, password)
if(isAuthenticated ==false)
{
// System.out.println("--------")
throw new IOException("Authorication failed")
}
//打开会话
Session sess = conn.openSession()
//System.out.println("cmd----")
//执行命令
sess.execCommand("ruby C:\\WhatWeb-master\\whatweb --output-xml http://216.139.147.75:443/")
// System.out.println("The execute command output is:")
InputStream stdout = new StreamGobbler(sess.getStdout())
BufferedReader br = new BufferedReader(new InputStreamReader(stdout))
while(true)
{
String line = br.readLine()
if(line==null) break
System.out.println(line)
}
// System.out.println("Exit code "+sess.getExitStatus())
sess.close()
conn.close()
// System.out.println("Connection closed")
}catch(IOException e)
{
System.out.println("can not access the remote machine")
}
}
}