在java中使用sshj时ssh时出现问题
我正在尝试远程连接到服务器以执行一些命令。 我对此很陌生,所以开始谷歌搜索。经过一番搜索,我尝试了一下:
我正在使用 sshj0.2.3.jar。
这是我的实现方式:
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("serverName");
try{
ssh.authPublickey("myUserId");
final Session session = ssh.startSession();
try{
final Command cmd = session.exec("net send myMachineName Hello!!!");
System.out.println(cmd.getOutputAsString());
System.out.println("\n Exit Status: "+cmd.getExitStatus());
}finally{
session.close();
}
}finally{
ssh.disconnect();
}
}
}
但我得到以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory at net.schmizz.sshj.DefaultConfig.(DefaultConfig.java:92) at net.schmizz.sshj.SSHClient.(SSHClient.java:133) at SSHTEST.main(SSHTEST.java:24) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:419) at java.lang.ClassLoader.loadClass(ClassLoader.java:643) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:345) at java.lang.ClassLoader.loadClass(ClassLoader.java:609) .....
我需要额外的罐子吗,多少额外的罐子我需要吗?我执行正确吗? 请帮忙。
提前致谢。
I am trying to get a remote connection to server to execute some commands.
I am new to this so started googling. After some search, I gave a try:
I am using sshj0.2.3.jar.
And here is how I implemented it:
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("serverName");
try{
ssh.authPublickey("myUserId");
final Session session = ssh.startSession();
try{
final Command cmd = session.exec("net send myMachineName Hello!!!");
System.out.println(cmd.getOutputAsString());
System.out.println("\n Exit Status: "+cmd.getExitStatus());
}finally{
session.close();
}
}finally{
ssh.disconnect();
}
}
}
But I get the folowing exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory at net.schmizz.sshj.DefaultConfig.(DefaultConfig.java:92) at net.schmizz.sshj.SSHClient.(SSHClient.java:133) at SSHTEST.main(SSHTEST.java:24) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:419) at java.lang.ClassLoader.loadClass(ClassLoader.java:643) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:345) at java.lang.ClassLoader.loadClass(ClassLoader.java:609) .....
Do I need extra jars,How many extra jars do i need. Am I implementing correctly?.
please help.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过谷歌搜索
sshj
,第一个结果揭示了答案:From googling
sshj
, the first result reveals the answer:是的,您需要 slf4j 的 jar(请参阅 2 页手册)
slf4j 附带API,然后是可插拔的实现,但建议的 slf4j-simple 应该就可以了
Yes, you need the jars for slf4j (see the 2-page manual)
slf4j comes with a API and then a pluggable implementation, but the proposed slf4j-simple should be just fine
slf4j 只是一个外观,您需要提供具体的实现。如果您并不真正关心日志记录,请坚持使用 slf4j 发行版中的 slf4j-nop-$(ver).jar。
slf4j is just a facade, and you need to supply a concrete implementation. If you don't really care about logging, stick in slf4j-nop-$(ver).jar that is present in the slf4j distribution.