Java Reference
In-Depth Information
{
public static void main(String [] args)
{
Vehicle porsche = new Vehicle(“Porsche”, “911”, 2003);
porsche.purchasePrice = 45000.00;
System.out.println(porsche);
}
}
Step 4: Set the CLASSPATH
Try to compile the CarDealer class using the -d flag:
javac -d c:\my_bytecode CarDealer.java
You should get a compiler error stating that the com.wiley.trans package
cannot be found and also that the Vehicle symbol cannot be resolved, similar
to the compiler errors in Figure 7.1.
The compiler cannot find the com.wiley.trans package because the compiler
does not know to look in c:\my_bytecode. The CLASSPATH environment
variable needs to be set.
CLASSPATH contains all the directories and JAR files where the necessary
bytecode can be found. A collection of bytecode files can be compressed
into a single file known as a Java Archive (JAR). If the bytecode you need
is in a JAR file, the JAR file needs to appear in the CLASSPATH
environment variable.
The easiest way to set the CLASSPATH variable is to use the set command,
as shown in Figure 7.2. Keep in mind that setting CLASSPATH in this manner
only sets it for that particular command prompt window.
The DOS command echo is used to see the current definition of an
environment variable, as demonstrated in Figure 7.2.
Figure 7.1
CarDealer will not compile until the CLASSPATH is set.
Search WWH ::




Custom Search