我正在尝试将 ExpectJ 作为 bigginner。我从互联网上得到了以下代码。这是在第一级抛出异常。代码和异常如下。我在 Mac 电脑上使用它。
package Linux;
import expectj.ExpectJ;
import expectj.Spawn;
import expectj.TimeoutException;
public class App {
public static void main(String[] args) {
try {
ExpectJ expectinator = new ExpectJ(5);
// Fork the process
Spawn shell = expectinator.spawn("/bin/bash");
// Talk to it
shell.send("echo Chunder\n");
shell.expect("Chunder");
shell.send("exit\n");
shell.expectClose();
}
catch(TimeoutException te){
System.out.println("Time!!");
}
catch(Exception e) {
System.out.println(e);
}
}
}
异常如下。
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at expectj.ProcessSpawn.<clinit>(ProcessSpawn.java:19) at expectj.ExpectJ.spawn(ExpectJ.java:57) at Linux.App.main(App.java:13) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 3 more
ExpectJ 2.0.7 也包括在内。“/bin/bash”路径也可以在 mac 中使用。我该如何解决这个问题?