Java Packages

The following is a typical Java package-related error:

Exception in thread "main" java.lang.NoClassDefFoundError: 
         basic/InvalidLookupLocator

Most of the code in this tutorial is organized into packages. To run the book's examples, the classes must be accessible from your classpath. For example, one of the programs in the basic directory is InvalidLookupLocator.java. This defines the class InvalidLookupLocator in the package basic. The program must be run using the fully qualified path name, as follows:

java basic.InvalidLookupLocator

(Note the use of ".", not "/".)

To find this class, the classpath must be set correctly for the Java runtime. If you have copied the file classes.zip, then you can find the class files for this tutorial there. You only need to reference this:

CLASSPATH=classes.zip:...

If you have downloaded the source files, then you can find the class files in subdirectories such as basic, complex, and so on. After compilation, the class files should also be in these subdirectories, for example, basic/InvalidLookupLocator.class. An alternative to using classes.zip is to set the classpath to include the directory containing those subdirectories. For example, if the full path is /home/jan/classes/basic/InvalidLookupLocator.class, then set classpath to

CLASSPATH=/home/jan/classes:...

An alternative to setting the CLASSPATH environment variable is to use the -classpath option to the Java runtime engine:

java -classpath /home/jan/classes basic.InvalidLookupLocator