Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Significance of dot(.) in classpath

 
Catherine austin
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The way to tell java or javac to search in current directory is to add a dot(.) to classpath".

Can any one explain what does this exactly mean?
According to i read earlier , the Following code:

> -classpath /com/foo/acct: /com/foo

Here the directory /com will NOT be searched .

I grasped that by using dot(.) we can refer to /com as follows :

-classpath /com/foo/acct:/com/foo.
Am i right? Kindly clear my confusion ..
I shall gratefull to you

 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your PATH and CLASSPATH are lists of directories - nothing more. they are separated in the list by a semicolon (on windows).

Usually, when you are working in java, your .java files are in a different directory than where your java.exe (or other executable depending on your OS) lives. so you will be in C:\home\fred\java\source. If you set up your PATH correctly, the OS will search all the directories in your path to see if that .exe is in one, and if so, it will run it.

CLASSPATH works in a similar fashion, except it is used by the JVM to find where your .class files are. so no matter what directory you are sitting in, if you type "java fred", the JVM will search all the directories listed in your CLASSPATH to find the "fred.class" file.

You can put a dot in your classpath to tell the JVM to always look in whatever directory you are currently sitting in when you call java. so if you are here:

c:\home\fred\java\classes, the JVM will look there, so long as you have a dot in your classpath. Note that if you don't have a classpath defined at all, the jvm looks in the current directory by default.

so, if you don't have a CLASSPATH defined (which is usually recommended for beginners), or if you have a dot in your CLASSPATH, you'll probably be fine.
 
Puneet Soni
Greenhorn
Posts: 18
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. is a convention in linux for present directory.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Puneet Soni wrote:. is a convention in linux for present directory.

it's not just linix
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic