我在Windows上安装了最新版本的Weka

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

我试图从命令行运行其中一种weka功能:

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

对此的引用:http://weka.wikispaces.com/Text+categorization+with+WEKA

但随后weka返回此错误:

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.

我已经设置了CLASSPATH环境变量以指向weka jar。

我做错什么了?

最佳答案

您在其中运行命令的Shell显然没有正确设置CLASSPATH环境变量,否则不会发生ClassNotFoundException。作为环境变量的替代方法,您可以使用命令行指定类路径:

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

您还可以通过在cmd shell中执行echo %CLASSPATH%来检查是否正确设置了环境变量。

09-30 15:21
查看更多