Set environmental variables in java

Once java is installed on your machine, ensure that the JAVA_HOME, java path and java classpath are set in the environment variables and points to the proper location.

Set Environment Variables:

How to set JavaHome:
How to set java path:
How to set java classpath:

Assume that java is installed at C:\j2sdk1.4.2_12 in your machine.

Set Java Home On Windows

  1. Right click on My Computer icon; open Properties option from the menu.
  2. Click the Advanced tab.
  3. Click the Environment Variables button.
  4. In the System Variables, check if JAVA_HOME is already exist if no, click New; two text fields, namely, Variable name and Variable value are displayed.
    1. Enter JAVA_HOME in the Variable name field.
    2. In the Variable value field, specify the location of the java installation directory. Example: C:\j2sdk1.4.2_12.

Note: To reflect your settings to current command prompt console, close it and open new one.

On Sun Solaris Machines or HP UNIX 11:

  1. Open /.dtprofile file in edit mode, add JAVA_HOME variable after the line export MyVar. Example: JAVA_HOME=/j2sdk1.4.2_12 //don’t use space before or after ‘=’ operator. export JAVA_HOME
  2. Log off the machine.
  3. Login into the machine.

On Suse Linux Machines:

  1. Open the /etc/profile file in the edit mode; add JAVA_HOME variable before the line export PATH.
    Example: JAVA_HOME=/j2sdk1.4.2_12 //don’t use space before or after ‘=’ operator.
    export JAVA_HOME
  2. Log off the machine
  3. Login into the machine.

Set java path:

  1. Right click My Computer icon; open Properties option from the menu.
  2. Click the Advanced tab.
  3. Click the Environment Variables button.
  4. In the System Variables, check if path variable already exist if not, click New; else click Edit; two text fields, namely, Variable name and Variable value are displayed.
    Case 1: If path variable is not defined
    1. Enter path in the Variable name field.
    2. In the Variable value field, specify the location of the java installation bin directory.
    3. Example: C:\j2sdk1.4.2_12\bin.

    Case 2: If path variable is defined

    Check location of the java installation bin directory in Variable value field, if it is not exist then, add at the end.
    Example: if ‘C:\j2sdk1.4.2_12\bin’ is already defined then path will look like ‘C:\jwsdp-1.4\jwsdp-shared\bin; C:\j2sdk1.4.2_12\bin;
    D:\ant\apache-ant-1.6.5\bin;.;’
    If ‘C:\j2sdk1.4.2_12\bin’ is not defined then path will look ‘C:\jwsdp- 1.4\jwsdp-shared\bin;D:\ant\apache-ant-1.6.5\bin;.;’

How to add a value if not exist:

    Add ‘C: \j2sdk1.4.2_12\bin’ path value at the end of existing path value that is
    C:\jwsdp-1.4\jwsdp-shared\bin;
    D:\ant\apache-ant-1.6.5\bin;
    C:\j2sdk1.4.2_12\bin;.;
    If you observe, in above path I added path ‘C: \j2sdk1.4.2_12\bin’ value after last semicolon and before dot – that means you have to make sure that always path variable value ends with ‘;.;’
    Finally your path always should be look like : ‘Value1; Value2; Value3;.;’.

Set java classpath:

    To set classpath you have to follow the same steps as path settings except instead of adding ‘C: \j2sdk1.4.2_12\bin’ add following two variable classpath values

    1. C:\j2sdk1.4.2_12\lib\dt.jar
    2. C:\j2sdk1.4.2_12\lib\tools.jar

    Finally classpath should like ‘value1;C:\j2sdk1.4.2_12\lib\dt.jar; C:\j2sdk1.4.2_12\lib\tools.jar;.;’

HTML Comment Box is loading comments...