Thursday, September 27, 2012

Setting the JAVA_HOME Environment Variable(Class Path) in Windows

Environment variables are global system variables accessible by all the processes running under the Operating System (OS). Environment variables are useful to store system-wide values such as the directories to search for the executable programs, the OS version, and the location of Windows binaries.After Installation of Java, you cannot compile programs until you have directory to your path environment variable if not already present, otherwise the tools won't be found when you try to compile and run programs. So you need to Set up Class path First. This tutorial explains how you can do that.If you want help on how to download or install Jdk, you can Read It Here

Setting Java Class Path

Classpath in Java is path to directory or list of directory which is used byClassLoaders to find and load class in Java program.
Here is Step by Step guide for setting Java Classpath in Windows
  • Go to Environment variable window in Windows by pressing "Windows + Pause" > Advanced > Environment variable " or you can go from right click on my computer than choosing properties and then Advanced and then Environment variable this will open Environment variable window.How to se Java Classpath in windows
  • Now specify your environment variable CLASSPATH and put the value of your JAVA_HOME\lib and also include current directory by including (dot or period sign).
  • Now to check the value of Java classpath in windows type "echo %CLASSPATH" in your DOS command prompt and it will show you the value of directory which are included in CLASSPATH.

    You can also set classpath in windows by using DOS command like :

    set CLASSPATH=%CLASSPATH%;JAVA_HOME\lib;
     
  • This way you can set classpath in Windows XP, windows 2000 or Windows 7 and 8, as they all come with command prompt.

Setting JAVA_HOME to JDK Installation Directory

JRE (Java Runtime) is needed for running Java programs. JDK (Java Development Kit) is needed for writing and running Java programs. JDK includes JRE plus development tools such as Java compiler.

Set JAVA_HOME to your JDK installation directory (e.g., "c:\Program Files\java\jdk1.6.0_xx"). JAVA_HOME is needed for running Tomcat and many other Java applications. JAVA_HOME is the directory you install your JDK.

For windows users (in Vista / Windows 7), you can set the JAVA_HOME permanently via "Control Panel" > "System" > "Advanced system settings". Switch to "Advanced" tab > "Environment variables" and choose "System Variables" (for all users) or "User Variables" (for this login user only). To create JAVA_HOME, choose "New". In variable "Name", enter " JAVA_HOME" and in variable "Value", provide the JDK installation directory.

You can optionally set JRE_HOME to the JRE base directory (e.g., "c:\Program Files\java\jre1.6.0_xx")

After setting all above environment variable you can compile and run your Java application freely.

No comments:

Post a Comment