user16168
user16168

Reputation: 655

Run java weka utility

I wonder how it is possible to use specific weka utility.

For exaple, I want to use the following utility TextDirectoryToArff.

I tried to run it as follows

javac TextDirectoryToArff.java

TextDirectoryToArff.java:21: package weka.core does not exist

and like following

java -jar /usr/share/java/weka-3.6.6.jar TextDirectoryToArff.java

and in this case weka starts and not the utility.

How it's possible to run the utility.

Upvotes: 2

Views: 2361

Answers (1)

Marco13
Marco13

Reputation: 54639

You first have to compile the TextDirectoryToArff.java file. This is done with javac. The error message in your case just indicates that you did not tell him where to find the weka classes that are required for the compilation. You can tell him where he can find these classes by specifying the classpath (cp) :

javac -cp /usr/share/java/weka-3.6.6.jar TextDirectoryToArff.java

This should create a file TextDirectoryToArff.class in the current directory.

In order to start this utility, you can simply call

java -cp .:/usr/share/java/weka-3.6.6.jar TextDirectoryToArff

Note that you do not use the -jar parameter, because you do not want to run what is inside the JAR, but the TextDirectoryToArff class directly. Therefore, you again have to specify the classpath. In this case, the classpath contains current directory (indicated by the .) (because it contains the TextDirectoryToArff.class file), and, separated from that with a :, the path to the weka JAR.

You'll also have to specify a directory name, so the full command line will be something like

java -cp .:/usr/share/java/weka-3.6.6.jar TextDirectoryToArff your/directory/name

Upvotes: 5

Related Questions