• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems setting PATH environment variable

 
Yong Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to compile and run the HelloWorldApp, but to compile it I had to specify the entire path:

C:\Java\jdk1.6.0_06\bin\javac HelloWorldApp.java

I understand that if I update the PATH variable, I won't have to specify the entire path every time I run the JDK executables.

To update the PATH variable, I followed the instructions from the installation notes. However, I had to add the PATH variable to both User Variables and System Variables...I simply chose 'New', named the variable 'PATH', and set the value to be 'C:\Java\jdk1.6.0_06\bin'. I did this for both User and System Variables.

I STILL have to specify the entire path in order to compile and run...what did I do wrong? Also, what's the difference between the PATH var. and the CLASSPATH var? I noticed that the value for my CLASSPATH var. (which is only under System Variables, not User Variables) is for an older JRE folder:

.;C:\Program Files\JavaSoft\JRE\1.3.1\lib\ext\QTJava.zip

What should I update this value to? (the current version of JRE I have installed, JRE1.6.0_06, does not have an 'ext' directory, or any equivalent QTJava file) I'm sorry for such a long question, but I would REALLY appreciate any help!!
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yong,

A couple of questions:

1. did you open a new command window after setting your Path variable? If you used the existing window, that would explain why it didn't pick up the change.

2. after opening a new command window, type path and see what it returns. is the java bin directory on that path? if not, there's a mistake somewhere in how you set up the variables.

I'm a bit surprised you don't have an existing path variable.

I'd just delete the old classpath entry and not worry about replacing it.
 
Kuldeep Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hiii
 
Yong Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muchas gracias!

I didn't realize that I needed to open a new command window...when I tried it today, it worked!

Question: when I type path, here's what's returned:

PATH=C:\Java\jdk1.6.0_06\bin\;C:\Java\jdk1.6.0_06\bin\

Why is the path repeated? Is it to show the paths of both User and System Variables?

Also, why not replace the CLASSPATH variable after deleting it? What does this variable do?

Thanks!!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kuldeep withDreams", please check your private messages. You can see them by clicking My Private Messages.

Yong: I'm not sure how this works on Windows (I use Linux most of the time), but yes, probably it's repeated because you put it in the User as well as in the System variables. You only need to put it in one of those two places (User if you want it for your login only, or System if you want to set it for all people who might use your computer).

CLASSPATH tells Java where to look for class files. Normally, with newer Java versions, you don't need to set it; Java will look for class files in the current directory if it's not set. You can also specify the classpath on the command line instead of as an environment variable, for example:

java -classpath C:\myproject\classes org.mypackage.MyMainClass

For more info, see this in our FAQ: How to set the classpath
[ April 22, 2008: Message edited by: Jesper Young ]
 
Yong Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Jesper, for your reply. I do have another question:

If the CLASSPATH variable tells Java where to look for class files, does that mean you can put .java files in different directories (other than the directory where your Java excutables: javac, etc) are located? If you do this, how do you compile...in other words, how would you compile a .java file that's located in a directory other than the current directory? Is it a bad practice to do this? Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it IS a bad practice to put your code/class files in the same dir as the JVM stuff. you really don't want to mix that stuff up.

generally, you'll create some kind of 'projects' directory, with sub-folders for each program.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic