Search code examples
javawindowsexceptionmachine-learningweka

Weka no main class found error


I installed the latest version of Weka on Windows

http://www.cs.waikato.ac.nz/ml/weka/

and I tried to run one of the weka features from the command line:

java weka.core.converters.TextDirectoryLoader -dir text_example > text_example.arff

which is a reference to this: http://weka.wikispaces.com/Text+categorization+with+WEKA

but then weka returns this error:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

Exception in thread "main" java.lang.NoClassDefFoundError: weka/core/converters/
TextDirectoryLoader
Caused by: java.lang.ClassNotFoundException: weka.core.converters.TextDirectoryL
oader
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: weka.core.converters.TextDirectoryLoader.  Progra
m will exit.

I already set the CLASSPATH environment variable to point to the weka jar.

What did I do wrong?


Solution

  • The shell you run the command in apparently doesn't have the CLASSPATH environment variable set properly, otherwise the ClassNotFoundException wouldn't occur. As an alternative to the environment variable you can specify the classpath using the command line:

    java -cp path/to/weka.jar weka.core.converters.TextDirectoryLoader -dir [...]
    

    You can also check whether the environment variable is set correctly by executing echo %CLASSPATH% in the cmd shell.