ExpectJ exception on expectinator.spawn

164 views Asked by At

I'm trying ExpectJ as bigginner. And I got following code from internet. This is throwing exception at first level. Code and exception as follows. I'm using it on Mac computer.

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 as follows.

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 also included."/bin/bash" path also available in the mac. How can I fix the issue?

1

There are 1 answers

2
Chetan Kinger On BEST ANSWER

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

It's pretty clear from this message that ExpectJ uses the apache-commons logging library internally. Make sure that the commons-logging jar is on your classpath when running your code.