Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: What are the necessary environment variables one should set after installing JDK on Windows and how?

This may be self evident to power Java programmers, but may not be so for those who are just starting the Java journey.

After downloading JDK from Sun and installing it on Windows, what environment variables should one set to use javac etc.. from command line tools like vi? (see Programming Java with Vim) Also, how does one set environment variables on Windows?

like image 809
Eugene Yokota Avatar asked Jul 06 '09 02:07

Eugene Yokota


2 Answers

See How to set the path in Windows 2000 / Windows XP for changing environment variables on Windows.

  1. From the desktop, right-click My Computer and click properties.
  2. In the System Properties window, click on the Advanced tab.
  3. In the Advanced section, click the Environment Variables button.
  4. Finally, in the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. Add or modify the path lines with the paths you wish the computer to access. Each different directory is separated with a semicolon as shown below.

I suggest adding a systems variable called JAVA_HOME and set that to

C:\Program Files\Java\jdk1.6.0_13

or wherever the installer installed Java.

Then add

;%JAVA_HOME%\bin

at the end of PATH variable. Note the semicolon is not a typo.

Another important environment variable that may come in handy later is CLASSPATH. For now, this does not need to be set, but nice to keep it in mind.

The class path tells SDK tools and applications where to find third-party and user-defined classes

like image 94
Eugene Yokota Avatar answered Nov 17 '22 02:11

Eugene Yokota


All you really need is to add the bin directory of the JDK to your PATH. To do this in windows, right-click on My Computer, click Properties, Advanced Settings, and Environment Variables. There, you can add the directory to your PATH variable (semicolon separated!).

Now, you can open a command prompt and just type javac, etc. Also, it doesn't sound like you are the IDE type, but if you are, I highly suggest Eclipse for getting started with Java.

like image 31
AdamC Avatar answered Nov 17 '22 02:11

AdamC