The CLASSPATH environment variable tells Java where to look for classes. Since Java does the search in a ''first-come-first-serve'' kind of manner, you'll have to take care where and what to put in your CLASSPATH. I, personally, never use the environment variable, since I'm working often on a project in different versions in parallel. The CLASSPATH would just mess up things, if you're not careful (or just forget to remove an entry). ANT offers a nice way for building (and separating source code and class files) Java projects.
But still, if you're only working on totally separate projects, it might be easiest for you to use the environment variable.

Setting the CLASSPATH

In the following we add the mysql-connector-java-3.1.8-bin.jar to our CLASSPATH variable (this works for any other jar archive) to make it possible to access MySQL databases via JDBC.

Win32 (2k and XP)

We assume that the mysql-connector-java-3.1.8-bin.jar archive is located in the following directory:
  • C:\Program Files\Weka-3-4
In the Control Panel click on System (or right click on My Computer and select Properties) and then go to the Advanced tab. There you will find a button called Environment Variables, click it.
Depending on, whether you're the only person using this computer or it is a lab computer shared by many, you can either create a new system-wide (you are the only user) environment variable or a user dependent one (recommended for multi-user machines). Enter the following name for the variable
  • CLASSPATH
and add this value
  • C:\Program Files\Weka-3-4\mysql-connector-java-3.1.8-bin.jar
If you want to add additional jars, you'll have to separate them with the path separator, the semicolon ; (no spaces!).

Unix/Linux

I assume, that the mysql jar is located in the following directory:
  • /home/johndoe/jars/
Open a shell and execute the following command, depending on the shell you're using:
  • bash
    export CLASSPATH=$CLASSPATH:/home/johndoe/jars/mysql-connector-java-3.1.8-bin.jar
  • c shell
    setenv CLASSPATH $CLASSPATH:/home/johndoe/jars/mysql-connector-java-3.1.8-bin.jar

Unix/Linux uses the colon : as path separator, in contrast to Win32, which uses the semicolon ;.

Note: the prefixing with $CLASSPATH adds the mysql jar at the end of the currently existing CLASSPATH.

Scripts

This is a little start script for Weka Explorer, which can be adjusted easily. It also loads a mysql-connector:
#! /bin/bash
# Path to weka
WEKA_PATH=~/weka/
# add mysql-connector (manually copied to weka path) and weka to classpath
CP="$CLASSPATH:/usr/share/java/:$WEKA_PATH/mysql-connector-java-5.0.5-bin.jar:$WEKA_PATH/weka.jar"
# use the connector of debian package libmysql-java
# CP="$CLASSPATH:/usr/share/java/:$WEKA_PATH/weka.jar"
echo "used CLASSPATH: $CP"
# start Explorer
java -cp $CP -Xmx500m weka.gui.explorer.Explorer


Cygwin

The process is like with Unix/Linux systems, but since the host system is Win32 and therefore the Java installation also a Win32 application, you'll have to use the semicolon ; as separator for several jars.

RunWeka.bat

See the detailed Notes on Windows for different versions of Weka in the Invocation section of the Java Virtual Machine article.