Using JAR Files on the CLASSPATH
My class path is configured to look in the classes.zip file provided by the JDK, followed by the root directory of the packages that I am developing. The CLASSPATH environment variable looks as follows:
CLASSPATH=c:\jdk1.1\lib\classes.zip;c:\java\projects
We can include the JAR file on the class path the same way any other path is put there. For example, if I wanted to keep all of the packages developed for this book in the BeansBook.jar file instead of keeping them in separate files, I could modify my CLASSPATH variable to look as follows:
CLASSPATH=c:\jdk1.1\lib\classes.zip;c:\java\projects\BeansBook.jar
Now the HTML file for running the PickleUser
applet can be restored to its original content by removing the
ARCHIVES tag. In this case the
PickleUser and
BeansBook.util.PickleButton classes will be loaded
from the BeansBook.jar file because it is part
of the class path.
This technique works just fine as long as the JAR file is not compressed. (You can create a JAR file without compression using the command-line option). If you want to put a compressed JAR file on the class path, it must contain all entries for every subdirectory involved. If you want a compressed JAR file to contain BeansBook/Simulator/Thermostat.class, the JAR file needs entries for the following:
BeansBook/
BeansBook/Simulator
BeansBook/Simulator/Thermostat.class
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access