我已经使用'net.schmizz.sshj.SSHClient'软件包连接到服务器。 下面是我的代码:
public class ConnectToServer {
String hostName = "10.250.176.6";
int port = 22;
public ConnectToServer(String hostName, int port) {
this.hostName = hostName;
this.port = port;
}
public void ssh() {
SSHClient ssh = new SSHClient();
String cmd = "ipconfig";
try {
ssh.connect(this.hostName, this.port);
ssh.isConnected();
final Process process = Runtime.getRuntime().exec(cmd);
ssh.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是,我遇到了一个错误:“ 线程“读取器”中的异常” java.lang.NoClassDefFoundError:org / bouncycastle / crypto / ec / CustomNamedCurves 。 我将bcprov-jdk15on-1.49和bouncycastle.jar添加到了我的类路径中。 请帮助我解决此错误。
完全例外:
08:46:05.526 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<kex done>>
08:46:05.528 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
08:46:05.528 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Negotiated algorithms: [ kex=curve25519-sha256@libssh.org; sig=ecdsa-sha2-nistp256; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
**Exception in thread "reader" java.lang.NoClassDefFoundError: org/bouncycastle/crypto/ec/CustomNamedCurves**
at net.schmizz.sshj.transport.kex.Curve25519DH.getCurve25519Params(Curve25519DH.java:60)
at net.schmizz.sshj.transport.kex.Curve25519SHA256.initDH(Curve25519SHA256.java:44)
at net.schmizz.sshj.transport.kex.AbstractDHG.init(AbstractDHG.java:46)
at net.schmizz.sshj.transport.KeyExchanger.gotKexInit(KeyExchanger.java:236)
at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:356)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:503)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:102)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:170) at net.schmizz.sshj.transport.Reader.run(Reader.java:59)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.crypto.ec.CustomNamedCurves
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
答案 0 :(得分:0)
清理您的项目或再次重建它。 如果问题仍未解决,请发布完整的异常,以便我们更加清楚。
答案 1 :(得分:0)
您的jar可能缺少其依赖项(或其中的一些依赖项)。如果它是Maven项目,建议您改用Maven。
可以在这里找到一个不错的教程:Maven in 5 Minutes
我认为,SSH客户端缺少org.Bouncycastle.crypto作为库(依赖项)。解决此问题的快速方法是也获得它的罐子。
答案 2 :(得分:0)
此问题可能是由于项目中使用了不同版本的 bouncycastle jar 所致。 解决办法是,