Forums Register Login

The dot in CLASSPATH

+Pie Number of slices to send: Send
"Note that you must have ‘.’ in your CLASSPATH in order for the files to compile."



The above line is from the book THINKING IN JAVA please can anyone explain what does it means and one thing more when i checked CLASSPATH on my laptop it was just showing "."
+Pie Number of slices to send: Send
technically, that is not true. You do not even have to have a CLASSPATH at all. But if you do, you want a dot.

CLASSPATH basically tells java where to find your .class files. If there is no CLASSPATH set, it will by default look in the current directory (I am assuming you are on a command line).

If you have a CLASSPATH variable set, it will ONLY look in the directories listed there. Odds are pretty good that most of the time, you will want to look in the current directory. and that is what the dot means - current directory, whatever that is at the time.
+Pie Number of slices to send: Send
Welcome to the Ranch

Most of the time you are better off not setting a system classpath at all. If somebody has told you to set a system classpath, they are mistaken.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:Welcome to the Ranch

Most of the time you are better off not setting a system classpath at all. If somebody has told you to set a system classpath, they are mistaken.



Why is that Campbell??? I thought if we set the class path, we can run the Java code from anywhere within the system, but if we do not set it we have to run from the bin directory where Java is installed right?
1
+Pie Number of slices to send: Send
 

Vineeth Menon wrote:

Campbell Ritchie wrote:Welcome to the Ranch

Most of the time you are better off not setting a system classpath at all. If somebody has told you to set a system classpath, they are mistaken.



Why is that Campbell??? I thought if we set the class path, we can run the Java code from anywhere within the system, but if we do not set it we have to run from the bin directory where Java is installed right?



If you're just writing small educational programs, and they all live in the same place, and all have the same simple classpath needs, and you don't run any other Java apps, then that's fine. Beyond that though, each project will be in its own location, and have its own set of classes and its own set of 3rd-party libraries, so each one will have different classpath needs. A single, system-wide classpath becomes useless. Each project will typically have a config file and/or startup script that sets the classpath for that app.

And no, you don't need to run from the bin directory where Java is installed, regardless of whether you do or do not set CLASSPATH. You're thinking of PATH, which is separate. It's fine to include Java's bin directory on your PATH.
+Pie Number of slices to send: Send
Ohh bummer, my bad...now I remember. Thanks for clearing it out Jeff
+Pie Number of slices to send: Send
 

Vineeth Menon wrote: . . . I thought if we set the class path, we can run the Java code from anywhere within the system, but if we do not set it we have to run from the bin directory where Java is installed right?

That is not a classpath. That sounds like a PATH.

Every app may have a particular location where .class files necessary for it can be found. Each app will have a different location for its dependencies. So you want a different classpath for each large app. When you are using small apps, and only require code in the current directory, that is where the JVM will look, as long as no other classpath is set.
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 925 times.
Similar Threads
head first ejb pg:57 client problem!!!please help urgent
servlet compilation
Problem with setting classpath
NoClassDefFoundError: org/apache/xalan/xslt/Process
JNI Probelm with Oracle iPlanet 7.0.9 Web Server
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:00:26.