Java中Path和ClassPath的区别
ClassPath是Java虚拟机 (JVM) 或Java编译器中的一个参数,系统或应用程序 ClassLoader 使用它来定位和加载存储在“.class”文件中的已编译Java字节码。另一方面,The Path也是一个环境变量路径,充当操作系统和开发人员之间的中介,告知二进制文件路径。
小路
PATH 是一个环境变量,用于查找和定位二进制文件,如“Java”和“javac”,并从命令行或终端窗口定位所需的可执行文件。要设置路径,我们应该在 PATH 环境变量中包含或提及 JDK_HOME/bin 目录。 PATH 不能通过提供命令来覆盖,PATH 仅由操作系统(OS)用于查找二进制文件。
句法
// To set PATH in the window OS.
set PATH=%PATH%;C:\Program Files\Java\JDK1.5.10\bin
// To set PATH in Unix OS
export PATH=${PATH}:/opt/Java/JDK1.5.10/bin
类路径
Classpath 是一个环境变量,应用程序 ClassLoader 或系统使用它来定位和加载存储在 .class 文件中的已编译Java字节码。设置类路径。可以通过在清单文件中添加类路径并使用 set -classpath 之类的命令来覆盖 CLASSPATH。 CLASSPATH 仅由Java类加载器用于加载类文件。
句法
// To set CLASSPATH in window OS.
set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\JDK1.5.10\lib
// To set PATH in Unix OS.
export CLASSPATH=${CLASSPATH}:/opt/Java/JDK1.5.10/lib
下表演示了 PATH 和 CLASSPATH 之间的区别 S. No. PATH CLASSPATH 1. 2. 3. 4. 5.An environment variable is used by the operating system to find the executable files. An environment variable is used by the Java compiler to find the path of classes. PATH setting up an environment for the operating system. Operating System will look in this PATH for executables. Classpath setting up the environment for Java. Java will use to find compiled classes. Refers to the operating system. Refers to the Developing Environment. In path variable, we must place .\bin folder path In classpath, we must place .\lib\jar file or directory path in which .java file is available. PATH is used by CMD prompt to find binary files. CLASSPATH is used by the compiler and JVM to find library files.