expectinator.spawn 上的 ExpectJ 异常

ExpectJ exception on expectinator.spawn

我正在尝试将 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.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 中使用。我该如何解决这个问题?

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory ....Caused by: java.lang.ClassNotFoundException:

从这条消息中可以清楚地看出,ExpectJ 在内部使用了 apache-commons 日志库。当 运行 您的代码时,请确保 commons-logging jar 在您的类路径中。