大家:
我正在尝试用java编写一个程序,它允许我通过ssh重启我的路由器。但是,我在尝试使用Expect4j发送路由器命令“restart”时遇到问题。这是我的代码:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Hashtable;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelShell;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import expect4j.Expect4j;
public class Router {
public static void main(String[] args) {
try {
JSch jsch = new JSch();
Session session = jsch.getSession("user", "host");
session.setPassword("password");
session.setConfig("StrictHostKeyChecking", "no");
session.connect(60 * 1000);
Channel channel = session.openChannel("shell");
Expect4j expect = new Expect4j(channel.getInputStream(),
channel.getOutputStream());
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
expect.send("restart");
channel.connect();
} catch (JSchException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是我得到的例外:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/oro/text/regex/Perl5Matcher
at expect4j.Expect4j.<init>(Expect4j.java:37)
at expect4j.Expect4j.<init>(Expect4j.java:61)
at Router.main(Router.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.oro.text.regex.Perl5Matcher
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
我真的不知道为什么输出会给我一个“未找到类”的例外。
您有任何想法或建议吗?
提前致谢。