Eckel introduced his own unit testing classes in his sample code. He called the automated testing "SimpleTest". My problem was that the sample Java applications could not find the SimpleTest classes, no matter how hard I tried to configure my environment.
Here was the error I kept getting at run time:
Exception in thread "main" java.lang.NoClassDefFoundError
The final solution turned out to be in Eckel's documentation all along, at http://mindview.net/Books/TIJ/. Here's what he said:
Set your CLASSPATH variable to include "." (the current directory) and the code directory.
I had already set my CLASSPATH to include the code directory, but I somehow missed the one about the dot "." so after I tried adding "." in the CLASSPATH and it worked! (For instructions, see below).
To work around the problem, I commented out all references to SimpleTest. And this allowed me to compile and run the sample code. But then I started aiming for test-driven programming, which made me more interested at making SimpleTest work. I read and re-read Eckel's documentation until I finally noticed the instructions about adding the "." to CLASSPATH.
How to set CLASSPATH in Mac OS X
Use a text editor like TextWrangler, which can open hidden files. Navigate to your home directory "~/"and look for a file called .bash_profile. If none, create the file and save it with that file name (no extensions). The file should contain the following line:
- "/Users/myhome/Development/tij" is where my Thinking in Java sample code is saved.
- The colon ":" is the separator. You can add additional CLASSPATH variables by separating them with a colon.
- Note the dot "." after the semicolon. This is what I kept missing as I read and reread Eckel's documentation. After I added the dot, everything worked!
Other programmers advise that it's better to just set the CLASSPATH from the command line, eg, by invoking:
java -classpathHowever, this is also tricky, so I prefer to set my CLASSPATH from the environment variables of Mac OS X.