Java Reference
In-Depth Information
Figure 7.2
The DOS command set is used to define an environment variable.
Step 5: Compile and Run the CarDealer Program
After your CLASSPATH is set, try to compile the CarDealer class again. Be sure
to use the -d flag, as follows:
javac -d c:\my_bytecode CarDealer.java
Setting the CLASSPATH Environment Variable
There are several ways to set environment variables, depending on your operating system.
If you are using a version of Windows that is Windows NT/2000/XP, then CLASSPATH can
be set in the Control Panel.
Open your Control Panel, and open the System icon. (Windows XP users need to click
Performance and Maintenance first.) You will see either the Environment or Environment
Variables tab. XP users need to click the Advanced tab and then click the Environment
Variables button. In either case, you should see the Environment Variables dialog window.
Click the New button for User Variables, or Edit if you already have a CLASSPATH envi-
ronment variable defined, and define your CLASSPATH. The window will look similar to
Figure 7.3.
Figure 7.3
Setting the CLASSPATH using the Environment Variables dialog window.
Click the OK button when you are finished. The settings will not take place in command
prompts that are currently open, but will take effect in all subsequent command prompts.
Be aware that setting the CLASSPATH in the Control Panel sets it for all command
prompt windows that you open. We might not want to set our CLASSPATH in the Control
Panel to only include c:\my_bytecode because we only want this directory in our CLASS-
PATH for our Vehicle example. Notice that I included a . in the CLASSPATH. The dot (.) rep-
resents the current directory.
There are many situations where you want folders and JAR files in your CLASSPATH all
the time. In these cases, set the CLASSPATH in the Control Panel so you do not have to set
it every time you open a command prompt.
Search WWH ::




Custom Search