How Classpath work in Java ?

Submitted By: javabuddy
Rating: (Not rated) (Rate It)
Share: Share By Email 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

(Not published)
star
starstar
starstarstar
starstarstarstar
starstarstarstarstar
 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.