Classpath
‱ Tells applications where to find third-party and user-
  defined classes
‱ The search order used by java tools
   ‱ Java platform (bootstrap) classes, any extension classes, and
     the class path
‱ Two ways to change class path
   ‱ -classpath option change the class path of java tools
   ‱ CLASSPATH environment variable
‱ The first approach is preferred

                                                                 1
Setting the Classpath
‱ -classpath
      ‱ jdkTool -classpath path1;path2...
         – eg. : javac –classpath d:projectclasses


‱ CLASSPATH environment variable
      ‱ eg. : SET CLASSPATH d:projectclasses




                                                       2
Classpath and Archive files
‱ Classes can be stored either in directories (folders) or in
  archive files ( jar files)
   ‱ eg. The Java platform classes are stored in rt.jar.

‱ Class path to the archive files
   ‱ For a .jar or .zip file that contains .class files, the path ends with
     the name of the .zip or .jar file

   ‱ eg. : javac –classpath d:projectutilClasses.zip
   ‱ eg. : javac –classpath e:xmlxalan.jar



                                                                              3
Multiple Path Entries
‱ Multiple path entries are separated by semi-colons
‱ To find class files in the following directories
   ‱ C:javaMyClasses
   ‱ C:javaOtherClasses
‱ set the classpath to:
   ‱ C:> java –classpath C:javaMyClasses;C:javaOtherClasses
‱ Order of classpath entries is important



                                                                  4

Classpath

  • 1.
    Classpath ‱ Tells applicationswhere to find third-party and user- defined classes ‱ The search order used by java tools ‱ Java platform (bootstrap) classes, any extension classes, and the class path ‱ Two ways to change class path ‱ -classpath option change the class path of java tools ‱ CLASSPATH environment variable ‱ The first approach is preferred 1
  • 2.
    Setting the Classpath ‱-classpath ‱ jdkTool -classpath path1;path2... – eg. : javac –classpath d:projectclasses ‱ CLASSPATH environment variable ‱ eg. : SET CLASSPATH d:projectclasses 2
  • 3.
    Classpath and Archivefiles ‱ Classes can be stored either in directories (folders) or in archive files ( jar files) ‱ eg. The Java platform classes are stored in rt.jar. ‱ Class path to the archive files ‱ For a .jar or .zip file that contains .class files, the path ends with the name of the .zip or .jar file ‱ eg. : javac –classpath d:projectutilClasses.zip ‱ eg. : javac –classpath e:xmlxalan.jar 3
  • 4.
    Multiple Path Entries ‱Multiple path entries are separated by semi-colons ‱ To find class files in the following directories ‱ C:javaMyClasses ‱ C:javaOtherClasses ‱ set the classpath to: ‱ C:> java –classpath C:javaMyClasses;C:javaOtherClasses ‱ Order of classpath entries is important 4