gpt4 book ai didi

java - sshj 0.9.0 抛出 NoClassDefFoundError : net/schmizz/sshj/SSHClient

转载 作者:行者123 更新时间:2023-12-01 13:48:38 26 4
gpt4 key购买 nike

我下面的代码抛出以下错误,我只能在 Google 上找到涉及日志记录错误的信息,但没有任何内容看起来像我的。我已经尝试安装中央 Maven 存储库所需的依赖项,但问题仍然存在。有谁知道为什么我上课没有发现异常?

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;

public class ConnectSSH {

public void connecting() throws IOException {

@SuppressWarnings("resource")
final SSHClient ssh = new SSHClient();

ssh.loadKnownHosts();
ssh.connect("*******");

try {
ssh.authPassword("*****", "*****");
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("*****");
System.out.print(IOUtils.readFully(cmd.getInputStream()));
cmd.join(5, TimeUnit.SECONDS);
System.out.print("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();

}

}

}

<小时/>

运行时抛出以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: net/schmizz/sshj/SSHClient
at ssh.liq_con.stats.ConnectSSH.connecting(ConnectSSH.java:16)
at ssh.liq_con.stats.App.main(App.java:8)
Caused by: java.lang.ClassNotFoundException: net.schmizz.sshj.SSHClient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
<小时/>

注意我有:

<dependency>
<groupId>net.schmizz</groupId>
<artifactId>sshj</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.49</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
<version>1.1.3</version>
</dependency>

最佳答案

您实际上不需要安装依赖项 - 它们是由 Maven 自动获取的。这可能是您的类路径的问题,您可以尝试添加为 public static void main(String[]):

的第一行
System.out.println(System.getProperty("java.class.path"));

确保类路径中有 sshj-0.9.0.jar

关于java - sshj 0.9.0 抛出 NoClassDefFoundError : net/schmizz/sshj/SSHClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143588/

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