• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The dot in CLASSPATH

 
Lovish Setia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 "."
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vineeth Menon
Ranch Hand
Posts: 78
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vineeth Menon
Ranch Hand
Posts: 78
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh bummer, my bad...now I remember. Thanks for clearing it out Jeff
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic