PATH and CLASSPATH Settings for Java

download PATH and CLASSPATH Settings for Java

of 3

Transcript of PATH and CLASSPATH Settings for Java

  • 8/12/2019 PATH and CLASSPATH Settings for Java

    1/3

    What is PATH and CLASSPATH in Java

    PATH and CLASSPATH are two most important environment variable of Java

    environment which is used to nd JDK binaries used to compile and run Java in

    windows and Linu and class les 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)Maindifference 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 Sstem or A%%lication

    ClassLoader to locate and load com%ile Java btecodes 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/ filewhich is re0uired b our Java a%%lication'

    ) 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 -classpathor

    -cpto 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& sstem to f ind 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:

    PATHis a s!stem variable used to tell to "S all locations of eec les#

    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\System32\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",i1.4.2.j"r;C:\Pro!r"m $iles

    )*8+\%"v"\jre1..0(2\lib\sl-4jsim,le1.4.2.j"r;C:\Pro!r"m $iles

  • 8/12/2019 PATH and CLASSPATH Settings for Java

    2/3

    )*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& sstem 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 "eword 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;

  • 8/12/2019 PATH and CLASSPATH Settings for Java

    3/3