views:

1341

answers:

6

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?

A: 

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>
Mike
In general, JAVA_HOME doesn't do anything. Some shell scripts written to launch Java applications (like ant) recognize this environment variable.
erickson
+1  A: 

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

OscarRyz
I did the following configuration set JAVA_HOME=C:\program files\java\jdk1.6.0_14set Path=JAVA_HOME\bin;%PATH%set classpath=.;I am still unable to compile the java program.
Just to be clear, it should have been set Path=__%__JAVA_HOME__%__\bin;%PATH%
erickson
I did install the jdk in C drive, then it worked. The problem was with the space in "Program Files". Thanks.
You can handle empty spaces if you add quotes: path=....;something;something;"c:\program files\java....\bin"
helios
A: 

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.

erickson
A: 

I'd suggest looking at the java tutorial.

http://java.sun.com/docs/books/tutorial/essential/environment/paths.html

Thorbjørn Ravn Andersen
A: 

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.

Jus12