非常感謝您的回答!有用!我用sftp上傳文件夾中的webapps文件夾中的Tomcat服務器。由於在server.xml autodeploy = true,我不必做HTTP PUT請求。這裏是我的代碼,基於此link:
String SFTPHOST = "1.2.3.4";
int SFTPPORT = 22;
String SFTPUSER = "root";
String SFTPPASS = "password";
String SFTPWORKINGDIR = "/home/username/apache-tomcat-8.0.23/webapps/";
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
try {
JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp) channel;
channelSftp.cd("..");
channelSftp.cd(SFTPWORKINGDIR);
File f = new File("path/to/war");
channelSftp.put(new FileInputStream(f), f.getName());
} catch (Exception ex) {
ex.printStackTrace();
}
Tomcat是否安裝在與Eclipse相同的機器上? – MadConan
不,它在不同的機器上。我可以使用Tomcat管理器來部署Web服務,但我想從具有http PUT請求的java代碼執行此操作。 – bloox