CCL Home Page
Up Directory CCL t019.html
slide

Jan K. Labanowski: "Tomcat, servlets, JSPs and other friends"

Java and CLASSPATH

Java classes are usually organized in packages which group together related classes. The classes in the package are placed under the some directorory. Related packages are usually organized hierarchically, i.e., as directory tree. E.g., class javax.servlet.http.Cookie is a part of javax.servlet.http package, and its bytecode resides in the file: /some/dir/javax/servlet/http/Cookie.class. If the Cookie class is needed by your Java application/servlet/applet, you need to either refer to it by its full name: javax.servlet.http.Cookie or place an import statement at the top of your source file:

package my.java.utils;
import javax.servlet.http.Cookie;
...
Cookie saveId = new Cookie("User", userId);
But how the java or javac knows where the /some/dir/javax/servlet/http/Cookie.class is located? From the CLASSPATH which either lists top directories for packages (in example above: /some/dir) or jar files.

Modified: Wed Feb 13 20:23:37 2002 GMT
Page accessed 362 times since Sun Feb 20 14:16:37 2011 GMT