How Classpath work in Java ?
Submitted By:
javabuddy
Rating:
(Not rated) (
Rate It)
Share:
By Email
Visit
Description
CLASSPATH is one of the most important concepts in java but I must say oftenly overlooked. This should be the first thing you should learn while writing java programs because without understand classpath you can't understand how java locate your class files.
So lets start with basic and then we will some example and improvisation of classpath.CLASSPATH is an environment variable which is used by JAVA to locate user defined classes.
You can override classpath defined by environment variable CLASSPATH by providing option "-cp" or "-classpath" while running your program and this is the best way to have different classpath for different applicaiton. General way to define classpath is in the startup script of any program. e.g.
CLASSPATH=/home/tester/classes
java -cp $CLASSPATH Test
By default CLASSPATH points to current directory denoted by "." and it will look for any class only in current directory.
Its also worth noting that when you use the -jar command line option to run your program as an executable JAR, then the CLASSPATH environment variable will be ignored, and also the -cp and -classpath switches will be ignored.
Comments (0)
Add Your Rating