aspose file tools*
The moose likes Beginning Java and the fly likes setting JAVA_HOME Explicitly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting JAVA_HOME Explicitly" Watch "setting JAVA_HOME Explicitly" New topic
Author

setting JAVA_HOME Explicitly

sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
I use windows server 2003 o.s.
I have jdk1.6.0_14 installed along with NetBeans IDE 6.7.1
I have problems with classpath setting.

When I Right click "MyComputer" --> select "properties" --> press "Advanced" tab --> click "Environment variables"

I have two boxes , one is "user variables for Administrator" ( In windows Xp, it is called "user variables) and the second box is with the name "System Variables"

Under "System Variables" already there is a variable named "path" , I selected it clicked "edit" button and added the following path to the already existing path

D:\Program Files\Java\jdk1.6.0_14\bin;

and when i compiled simple "hello world !" program , it compiles. so far so good.

But when i remove the path which i have added in "path" variable and create a seperate variable under "System variables" section with "variable name" as "JAVA_HOME" and "value" as D:\Program Files\Java\jdk1.6.0_14\bin; it's not working. Why?

I want a seperate variable under which i want to add all the values regarding java.

also when i try this path under "path" variable of "user variables " section it does not work.Why?
also if i create "new" variable with "Java_Home" under this(user variables) section also and add the path similar to the above mentioned one. It doesn't work.

Why it only works in "path" variable of system variables section. Same is the case with "windows XP" , incase if somebody are about to complain about "server os".

"SCJP5 | SCWCD5| DEVELOPER"
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

But when i remove the path which i have added in "path" variable and create a seperate variable under "System variables" section with "variable name" as "JAVA_HOME" and "value" as D:\Program Files\Java\jdk1.6.0_14\bin; it's not working. Why?

JAVA_HOME is not the same as PATH. JAVA_HOME is used to tell where your JDK is (D:\Program Files\Java\jdk1.6.0_14). PATH is used to find the commands you execute at the command prompt.

also when i try this path under "path" variable of "user variables " section it does not work.Why?

It should work. BUT. When you say "when i compiled simple "hello world !" program , it compiles.", do you mean that you compiled it on the command line ?


[My Blog]
All roads lead to JavaRanch
sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
yes, i compiled using "command prompt" like "javac Helloworld.java"
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

also when i try this path under "path" variable of "user variables " section it does not work.Why?

Can you tell us again the exact variable name and the exact value that you used ?

Also, after setting the variable, you need to open a new command prompt. The changes will not be reflected in the current opened window.
sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
ok, it's my mistake. The program compiles and runs even when i kept the D:\Program Files\Java\jdk1.6.0_14\bin; in "path" variable of "user variables" section.

now which in which "path" variable i put this value "D:\Program Files\Java\jdk1.6.0_14\bin;" in user variable's section "path" or in System variables "path" and why?

Also, since my program is working fine giving D:\Program Files\Java\jdk1.6.0_14\bin; in path value. Why should i create a variable "java_home" and give the value as " D:\Program Files\Java\jdk1.6.0_14;" , what is the use of it. and where should i create it, In user variable section or in system variable section?why? can you tell me what more can i add in "java_home" variable value. can i put "My_java_home" (or any other name) instead of "java_home". I sometimes heard of "catalina_home" also. Any speciality with these names?

I could see that in system variable section there is a variable with the name "classpath" , what is the use of it?

thanks a lot Christophe for your replies so far. these are my very long term doubts.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

System variables will be visible to all users, whereas user variables only by you (reference).

About JAVA_HOME. One reason is that some applications use it to find out where you JDK is. Another reason is that it can help you if you have several versions of your JDK on your machine :
JAVA_HOME=D:\Program Files\Java\jdk1.6.0_14
PATH=%JAVA_HOME%\bin
Here, you can change your JAVA_HOME, without having to change the path.

can i put "My_java_home" (or any other name) instead of "java_home".

No. Nobody would recognize it.

I sometimes heard of "catalina_home" also.

That's used by Tomcat, to tell where your Tomcat installation is. In general, XXXX_HOME helps to tell where XXXX is.
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

I'm not sure if it will give an error or not, but the path separator ";" shouldn't be in your JAVA_HOME variable. Just the path, no punctuation.
In your Path, you can then append ";%JAVA_HOME%" to your Path variable.

Also, it is better to specify as JAVA_HOME your real Java home, meaning "D:\Program Files\Java\jdk1.6.0_14", and then add ";%JAVA_HOME%\bin" to your path variable.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Dieter Quickfend wrote:I'm not sure if it will give an error or not, but the path separator ";" shouldn't be in your JAVA_HOME variable. Just the path, no punctuation.

That's right, appending a ";" will make it unusable.
sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
can you tell me what more can i add in "java_home" variable value.


could see that in system variable section there is a variable with the name "classpath" , what is the use of it?


Thanks Christophe and Dieter , almost all questions are clarified. Can you clarify the above ones also.

That's right, appending a ";" will make it unusable.


If Java_home can take some more values(besides jdk path) the usage of ; (path seperator ) is necessary isn't it? If java_home cannot take any other values then ofcourse there is no need of ;
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

JAVA_HOME does not take other values. Only the path to your JDK.
sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
Thank you ALL.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: setting JAVA_HOME Explicitly