I want to convert text files to arff files in a directory. When I run the below command in a linux terminal:
java weka.core.converters.TextDirectoryLoader -dir weka
... I get following error:
Exception in thread "main" java.lang.NoClassDefFoundError: weka/core/converters/TextDirectoryLoader
Caused by: java.lang.ClassNotFoundException: weka.core.converters.TextDirectoryLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: weka.core.converters.TextDirectoryLoader. Program will exit.
Please suggest how to resolve this error.
This error message tells us that the TextDirectoryLoader class is not present on your current search path. Probably it was not installed with your version of Weka.
According to their wiki, this class is only available for Weka versions greater than 3.5.3. Check your installation directory again and look for this class. Else use TextDirectoryToArff
How to change the classpath
You have to edit (sudo gedit or sudo vim) the .bashrc file located at your home directory (~) and add this line:
export CLASSPATH=$CLASSPATH:[new_path]
Where your [new_path] is something like /home/users/username/downloads/weka/weka.jar
EDIT: Noticed that you should add the weka.jar to the classpath, and not the weka installation directory.