I have JDK installed in Vista. I want to run java
from the command line. How do I configure the path variable?
If I'm not able to set the JAVA_HOME
variable, what is an alternative?
I have JDK installed in Vista. I want to run java
from the command line. How do I configure the path variable?
If I'm not able to set the JAVA_HOME
variable, what is an alternative?
If the java program is available in your path then you should just be able to do;
c:> java -classpath somedir com.example.Main
if java isn't available to you then you can do
c:> SET JAVA_HOME=c:\path\to\java
c:> <same java stuff from above>
Open My Conputer -> General Settings -> Environment variables and add as global
Key:JAVA_HOME Value:C:\jsdk etc. etc.
And then modify the Path variable
Value ( type at the end )
....something;something;something;%JAVA_HOME%\bin
Reopen your command prompt and type
javac
And see if it works
EDIT
Moved my comment to the answer
The command prompt has some problems dealing with the empty space.
What I usually do is install the jdk directly on C: to get rid of space in "Program Files"
So installing it directly in C: will give you an "spaceless" path to the executable:
C:\jdk1.6.0_14\bin\javac
Instead of
C:\Program Files\Java\jdk1.6.0_14\bin\javac
Some times you'll get: C:\Program "executable not found" or something like that.
Installing directly on C: does the trick
Use the -classpath
option for the java
command to specify where your classes are.
The value of the classpath option is a list of directories, JAR archives, and ZIP archives that contain classes, structured into directories that mirror the classes' package structure. The list uses the path delimiter, which is plaform specific: on Windows, it is ";
", other platforms use ":
".
Using the CLASSPATH
environment variable is discouraged because changes for one program are likely to interfere with the operation of other programs.
I'd suggest looking at the java tutorial.
http://java.sun.com/docs/books/tutorial/essential/environment/paths.html
There is some problem with Vista and the path variable containing %JAVA_PATH%
if the JAVA_PATH
value has spaces.
I fixed this manually by setting the %JAVA_PATH%
to c:\program files\Java\<whatever>
and then added to c:\program files\Java\<whatever>\bin
to the Path
variable in Vista.