gpt4 book ai didi

java - 使用 JAVA Axis 开发的 SSH 的 Web 服务中出现错误

转载 作者:行者123 更新时间:2023-12-01 05:17:19 25 4
gpt4 key购买 nike

我尝试在 JAVA(axis)中创建一个 Web 服务,它连接到 SSH 中的服务器所以我使用了一个名为 ganymed 的 api,它在 java 中运行良好

但是当我尝试使用 AXis 获取 WSDL 文件时,我遇到了一个奇怪的错误“Exception - java.lang.NoClassDefFoundError : ch/ethz/ssh2/StreamGobbler”

这是我的文件 java :

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 ganymed
{
public static string ssh()
{ String res="";
String hostname = "10.0.0.20";
String username = "students";
String password = "xxxx";
try
{
/* Create a connection instance */

Connection conn = new Connection(hostname);

/* Now connect */

conn.connect();

/* Authenticate.
* If you get an IOException saying something like
* "Authentication method password not supported by the server at this stage."
* then please check the FAQ.
*/

boolean isAuthenticated = conn.authenticateWithPassword(username, password);

if (isAuthenticated == false)
throw new IOException("Authentication failed.");

/* Create a session */

Session sess = conn.openSession();

sess.execCommand("uname -a && date && uptime && who");

System.out.println("Here is some information about the remote host:");

/*
* This basic example does not handle stderr, which is sometimes dangerous
* (please read the FAQ).
*/

InputStream stdout = new StreamGobbler(sess.getStdout());

BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

while (true)
{
String line = br.readLine();
if (line == null)
break;
res +=line;

}

/* Show exit status, if available (otherwise "null") */

System.out.println("ExitCode: " + sess.getExitStatus());

/* Close this session */

sess.close();

/* Close the connection */

conn.close();

}
catch (IOException e)
{
e.printStackTrace(System.err);
System.exit(2);
}
return res;
}

}

最佳答案

NoClassDefFoundError 的明显原因是类路径中没有特定的类,因此您需要将包含 ch/ethz/ssh2/StreamGobbler 类的 jar 添加到类路径中,或者您需要检查原因如果您期望它在类路径中不可用。

看看这个链接:http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html

关于java - 使用 JAVA Axis 开发的 SSH 的 Web 服务中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10969080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com