In order for javac to compile the code and for java to execute it, they need to know the location of the files that compose the application. In Chapter 2, Java Language Basics, while explaining the format of the javac and java commands, we described how the -classpath option allows you to list all of the classes and third-party libraries your application is using (or, in other words, depends on). Now, we will talk about setting this list.
Setting the classpath
Manual setting
There are two ways to set it:
- Via the -classpath command-line option
- Via the CLASSPATH environment variable
We will describe how to use the -classpath option first. It has the same format in the javac and java commands:
-classpath dir1;dir2\*;dir3\alibrary...