• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classpath doubt  RSS feed

 
david colais
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys...
I have a doubt regarding the classpath.The thing is when we specify the classpath as an environment variable i have not added the '.' (which specifies that the class files should be searched in the current directory) but still the the files inthe current directory can be run.Is this a default behavior of java???Please explain...
 
Anshuman Chakraborty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The behavior is to look for the requested classes in the current directory first.
When not found, it tries to find the same in the path specified by environment classpath (from left to right).
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anshuman Chakraborty wrote:The behavior is to look for the requested classes in the current directory first.
When not found, it tries to find the same in the path specified by environment classpath (from left to right).


Sorry, but this isn't correct. Java won't look in the current directory if CLASSPATH is set and the current directory isn't on it.

To the OP: You need to challenge the assumptions that led to the initial question -- for example, if "." is not on the CLASSPATH, perhaps the directory name itself is explicitly there? Or perhaps your CLASSPATH environment variable isn't being used, for example because you've misspelled it, or because you're using a command prompt that was runing before you set the variable (you need to re-run CMD.EXE to get a command shell with the value of CLASSPATH set). Or perhaps it's not the classes in the current directory that are being picked up, but rather some other like-named classes located elsewhere?
 
Anshuman Chakraborty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Ernest,
I misinterpretted it initially.
 
david colais
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ernest Friedman-Hill: I checked and "." is not in the classpath.
And the directory name is not explicitly there and the classpath's value is not mis-spelt.
And my cmd prompt was not running before i set the value of the classpath.
And the classes which are being picked up are only present in the current directory and there are no like-named classes located elsewhere.
please help...
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
heekphovam heek please check your PMs.

Setting the classpath. Where are the files being compiled and what exactly is the classpath value?
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anshuman Chakraborty wrote:The behavior is to look for the requested classes in the current directory first.
When not found, it tries to find the same in the path specified by environment classpath (from left to right).
If an environment variable has been set, the current directory is not sought through automatically. It is usually better not to set a CLASSPATH environment variable at all.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!