File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes classpath and path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath and path" Watch "classpath and path" New topic
Author

classpath and path

Gopi Krrishna
Greenhorn

Joined: Feb 15, 2006
Posts: 12
What are the values to be entered in PATH environment variable and CLASSPATH environment variable?
I have my jdk in the following path k:\program files\java\jdk1.5.0.
I already entered CLASSPATH environment variable with "k:\program files\java\jdk1.5.0" and PATH as "k:\program files\java\jdk1.5.0\bin".
Still this doesnt work.
What should be my PATH and CLASSPATH?
Help me.


SCJP 1.4
Roy Simon
Ranch Hand

Joined: Aug 26, 2005
Posts: 62
k:\program files\java\jdk1.5.0 this will allow the imports of all the class files that are there in "k:\program files\java\jdk1.5.0" folder. if u want to include a jar file in ur class path use
eg
"k:\program files\java\jdk1.5.0\src.jar" -- something like this....

k:\program files\java\jdk1.5.0\bin is fine to run and compile java programs from anywhere on ur computer..

Hope this helps!!
Regards
Simon
[ April 01, 2006: Message edited by: Roy Simon ]
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
java while installing itself will set the path for its packages. where as the user defined packages has to be informed to the compiler. so make the classpath to say that my class files are at this location.

so right now all the class files available at k:\program files\java\jdk1.5.0 will be made available to the compiler. and i think u would have got the error class not found. if u have encountered this error then probably u would have entered ur import package.*; wrongly.


Regards,
vignesh
Gopi Krrishna
Greenhorn

Joined: Feb 15, 2006
Posts: 12
Thanks Simon Roy and Vignesh Hariharan for your valuble suggestions. I've clarified the problem.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Note that everything Roy and Vignesh said about CLASSPATH is wrong. There are no classes in that directory. There are no classes in "src.jar". If you put a directory on the CLASSPATH, jar files in that directory are not searched for classes.

Classes that come in the JDK are not loaded via the CLASSPATH environment variable; therefore, you never need to set CLASSPATH to include the JDK install directory or any component thereof.

I'm sorry if I sound a little peeved, but people have been asking dozens of CLASSPATH questions in the last few days, all of them apparently having been told to set it to the JDK home directory, and all of them have been getting these truly awful answers from people who themselves don't know any better. I'm frustrated with the folks who answer questions when they shouldn't; perhaps more people could read this.

The very best advice about CLASSPATH: go to the control panel and [b]remove any value that you've set.[/i] With no value set, you'll get the default value, which includes the current directory and nothing else. This is perfect.

When you learn more about Java, you'll eventually know enough to decide whether to set it yourself, and what to set it to. Until then, just don't set it at all -- you'll be glad you listened to me.


[Jess in Action][AskingGoodQuestions]
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Ernest Friedman-Hill:
Note that everything Roy and Vignesh said about CLASSPATH is wrong. There are no classes in that directory. There are no classes in "src.jar". If you put a directory on the CLASSPATH, jar files in that directory are not searched for classes.

Classes that come in the JDK are not loaded via the CLASSPATH environment variable; therefore, you never need to set CLASSPATH to include the JDK install directory or any component thereof.

I'm sorry if I sound a little peeved, but people have been asking dozens of CLASSPATH questions in the last few days, all of them apparently having been told to set it to the JDK home directory, and all of them have been getting these truly awful answers from people who themselves don't know any better. I'm frustrated with the folks who answer questions when they shouldn't; perhaps more people could read this.

The very best advice about CLASSPATH: go to the control panel and [b]remove any value that you've set.[/i] With no value set, you'll get the default value, which includes the current directory and nothing else. This is perfect.

When you learn more about Java, you'll eventually know enough to decide whether to set it yourself, and what to set it to. Until then, just don't set it at all -- you'll be glad you listened to me.


+1


Tony Morris
Java Q&A (FAQ, Trivia)
Roy Simon
Ranch Hand

Joined: Aug 26, 2005
Posts: 62
I didnt say that if u include a folder in the classpath the jar files in that folder will be searched... for jar files, the jar file has to be included in the classpath... only the classfiles which are immediately in that folder will be included....

Regards
Simon
Roy Simon
Ranch Hand

Joined: Aug 26, 2005
Posts: 62
k:\program files\java\jdk1.5.0 this will allow the imports of all the class files that are there in "k:\program files\java\jdk1.5.0" folder. if u want to include a jar file in ur class path use
eg
"k:\program files\java\jdk1.5.0\src.jar" -- something like this....

k:\program files\java\jdk1.5.0\bin is fine to run and compile java programs from anywhere on ur computer..


what i meant by import there is that u can just say ClassName obj = new ClassName if the folder location is the classpath and that particular class is not in the classpath.... I think that will work.... (where my test file is in another location..).And abt using jars(with class files in it)... I have bashed their path in the classpath and then imported classes in the jar using the import command.... the Eg of src.jar was only and example.. ok keep it as foo.jar .. I dont see what is wrong with this answer

Correct me if i am wrong, may be there is a misinterpretation here

Regards
Simon
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
Originally posted by Ernest Friedman-Hill:

Classes that come in the JDK are not loaded via the CLASSPATH environment variable; therefore, you never need to set CLASSPATH to include the JDK install directory or any component thereof.



Originally posted by vignesh hariharan:

java while installing itself will set the path for its packages. where as the user defined packages has to be informed to the compiler. so make the classpath to say that my class files are at this location.


i never said that the classpath is set for the packages that comes from the jdk is done through CLASSPATH environmental variables explicitly by the installer. But one thing.. i think the compiler is informed after the installation of the jdk, that when it encounters java.io.*; (something like this) searches automatically the exact location of those classes(which are not explicitly defined in the CLASSPATH).

that is why i said that "java while installing itself will set the path for its packages"

sorry sir... if i am wrong anyway please help me out rather getting aggravated. anyway i apologise if i am wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath and path