Sie sind auf Seite 1von 3

What is PATH and CLASSPATH in Java

PATH and CLASSPATH are two most important environment variable of Java
environment which is used to fnd JDK binaries used to compile and run Java in
windows and Linu and class fles which are compile Java b!te codes
Difference between PATH and CLASSPATH in Java
Here are some of the common difference between PATH vs CLASSPATH in Java :
1)Main difference between PATH and CLASSPATH is that PATH is an environment variable which is
used to locate J! binaries li"e #java# or #javac# command used to run $ava %ro&ram and com%ile $ava
source file' (n the other hand CLASSPATH environment variable is used b) S)stem or A%%lication
ClassLoader to locate and load com%ile Java b)tecodes stored in 'class file'
*) +n order to set PATH in Java )ou need to include J!,H(M-.bin director) in PATH environment
variable while in order to set CLASSPATH in Java )ou need to include all those director) where )ou have
%ut either )our 'class file or JA/ file which is re0uired b) )our Java a%%lication'
1) Another si&nificant difference between PATH and CLASSPATH is that PATH can not be overridden b)
an) Java settin&s but CLASSPATH can be overridden b) %rovidin& command line o%tion -classpath or
-cp to both #java# and #javac# commands or b) usin& Class2Path attribute in Manifest file inside JA/
archive'
3) PATH environment variable is used b) o%eratin& s)stem to find an) binar) or command t)%ed in shell4
this is true for both 5indows and Linu6 environment while CLASSPATH is onl) used b) Java
ClassLoaders to load class files.$ar files'
PATH:
PATH is a s!stem variable used to tell to "S all locations of eec fles#
C:\tibco\tibrv\8.4\bin;C:\tibco\tibrv\8.1\bin;C:\tibco\tibrv\8.3\bin;C:\tibco\tibrv\8.1\bin
;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System
32\WindowsPowerShell\v1.0\;C:\tibco\tibcojre4\1..0\bin;C:\Pro!r"m
$iles\%"v"\jd&1.'.0(0\bin;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\bin;C:\tibco\ems\.0\bin;
CLASSPATH:
CLASSPATH environment variable is used by System or Application Class Loader to locate and
load compile Java bytecodes stored in .class file. $t is Pure java variable w!ic! is used to tell
locations of all jar"#ip$classes% files to Compiler.
&'ample() *f we are usin+ JD,C Driver t!en we need to -eep classes./.jar in classpat!*f we are
usin+ sevlets future t!en we need to -eep servlet)api.jar in classpat!
C:\tibco\tibrv\8.4\lib\tibrvn"tive.j"r;C:\tibco\tibrv\8.1\lib\tibrvj.j"r;C:\tibco\tibrv\8.3\lib
\tibrvn"tive.j"r;C:\tibco\tibrv\8.1\lib\tibrvj.j"r;C:\tibco\tibcojre4\1..0\bin\client;C:\Pr
o!r"m $iles )*8+\%"v"\jre1..0(2\lib\jms.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\tibjms.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\tibcry,t.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\tibjms"dmin.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\sl-4j.",i.1.4.2.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\sl-4j.sim,le.1.4.2.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\tibrvjms.j"r;C:\Pro!r"m $iles
)*8+\%"v"\jre1..0(2\lib\tibjms",,s.j"r;
How to set PATH and CLASSPATH in 0indows and 1ni'
+f )ou are familiar with (S o%eratin& s)stem and how to use command %rom%t in 5indows or shell in
Linu6 settin& PATH and CLASSPATH is trivial e6ercise' 7oth PATH and CLASSPATH are environment
variable and can be set usin& export in Linu6 and usin& set "e)word in (S and 5indows as shown
below:
Command to set PATH in 5indows
set PATH=%PATH%;C:\Program Files\Java\JD!"#"$%\&i'
Command to set PATH in 89+:.Linu6
export PATH = ()PATH*:+opt+Java+JD!"#"!,+&i'
Loo" at the difference between two commands4 in Linu6 use colon;:) as se%arator and in 5indows use
semi2colon;<) as se%arator'
Command to set CLASSPATH in windows
set C-A..PATH=%C-A..PATH%;C:\Program Files\Java\JD!"#"$%\li&
Command to set CLASSPATH in 8ni6.Linu6
export C-A..PATH= ()C-A..PATH*:+opt+Java+JD!"#"!,+li&
Also don=t for&et to include current director)4 denoted b) dot;') to include in CLASSPATH4 this will ensure
that it will loo" first on current director) and if it found the class it will use that even if that class also e6ists
in another director) which e6ists in CLASSPATH'
JAVA_HOME and JRE_HOME are not used by Java itself. Some third-party programs (for example
Apache Tomcat) expect one of these environment variables to be set to the installation directory of the
JD or J!". #f you are not using soft$are that re%uires them& you do not need to set JA'A()*+" and
J!"()*+".
CLASSPATH is an environment variable $hich contains a list of directories and , or JA! files& $hich
Java $ill loo- through $hen it searches for Java classes to load. .ou do not normally need to set the
/0ASS1AT) environment variable. #nstead of using this environment variable& you can use the -cp or
-classpath option on the command line $hen using the javac and java commands.
PATH is an environment variable used by the operating system (2indo$s& +ac *S 3& 0inux) $here it
$ill loo- for native executable programs to run. .ou should add the &i' subdirectory of your JD
installation directory to the 1AT)& so that you can use the javac and java commands and other JD
tools in a command prompt $indo$. The JD installation instructions explain ho$ to set 1AT).
Some #mp path4
CATAL*2A3H45&( C(6Pro+ram 7iles6apac!e)tomcat)8.9.:;< then set CLASSPATH variable to
CLASSPATH ( C(6Pro+ram 7iles6apac!e)tomcat)8.9.:;6lib<
then finall) edit %ath variable to PATH( .<=CATAL*2A3H45&=6bin<

Das könnte Ihnen auch gefallen