Friday 1 September 2017

Java CLASSPATH

Cited from How to Set CLASSPATH for Java in Windows and Linux

Classpath in Java is the path to directory or list of the directory which is used by ClassLoaders to find and load class in Java program. Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command line option or Class-Path attribute in manifest.mf file inside JAR file in Java. CLASSPATH is an environment variable which is used by Java Virtual Machine to locate user defined classes. 

JAVA_HOME is another environment variable used to find java binaries located in JDK installation directory.

It's also worth noting that when you use the java -jar command line option to run your Java program as an executable JAR, then the CLASSPATH environment variable will be ignored, and also the -cp and -classpath switches will be ignored. In this case, you can set your Java classpath in the META-INF/MANIFEST.MF file by using the Class-Path attribute. In short Class-path attribute in manifest file overrides classpath specified by -cp, -classpath or CLASSPATH environment variable.


No comments:

Post a Comment