This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Classpath Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath Question" Watch "Classpath Question" New topic
Author

Classpath Question

Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Hi All.
Just when I thought I had it all figured out...
My directory structure(s) for two concurrent releases are as follows...
/home/myself/Release1/a/b/c //lets call this dir1
/home/myself/Release2/a/b/c // dir2
My CLASSPATH points to /home/myself/Release1
All java files in both directories (dir1 & dir2) have a package statement at the beginning of the file as follows :-
package a.b.c;
The question --> If I go to the dir2 & try to compile a file, say myFile.java, Why is it compiling ??? It should not compile since my CLASSPATH is pointing to Release1 & not Release2.
Just to be sure that the myFile.java file that was getting compiled was in the Release 2 and not Release 1, I checked the timestamps of the myFile.class file & it was current in the dir2 & old in dir1.
Any ideas whats going on ?? How is the Javac able to fine the Release2 code even when the CLASSPATH only points to Release 1 ???
thanks in advance...


Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Preetham M
Greenhorn

Joined: Sep 18, 2002
Posts: 12
Since you have all the required files already present in the classpath /home/myself/Release1, when you compile the file present in release2, it looks for the necessary files in the classpath and since they are present in Release1 in the classpath, it uses them to compile your file in Release2.
Remove the Release1 from your directory and it will not compile, unless all your files are not present in the current directory.
Hope it helps,
thanks,
Preetham.
Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Thanks for your response...
I renamed Release1 to Release1_hj. The file in Release2 still compiled fine.
When I compile a standalone (which does not need any other file in the package) file in Release 2, it does not refer to release 1 files, in anyway. Moreover, as I said before, the timestamp on the class file of this file is current, which means that it was this file (in release2) that was compiled and not the same file in Release1.
Any guesses on whats going on ?
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Do you have the current directory (".") as part of your classpath?


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Yes. I did.
I removed it from the CLASSPATH... still compiles fine !
Looks like javac compiler is really in a good mood !
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Himanshu,
Here's a couple of suggestions....
1. I've noted a reference to a posting I made at the Ranch concerning classpaths which may help you out (maybe it'll shed some light):
Java Ranch discussion re: classpath
2. It may be best to sort of dissect this into smaller pieces, i.e.-move your program which uses the package into an entirely different directory and move the package source code into a 2nd entirely different directory. Modify your classpath for the new locate where you placed your package. Rename your compiled class files, Then try your compiles. Take the next step and actually try to run the code. Consider also how you are trying to compile your code - using the -d option? etc.
Hopefully this will help you solve your mystery. Good luck!
Janet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classpath Question
 
Similar Threads
looking for .class-files in current directory by default?
Development: trouble with import and classpath
Difference JSP File & JSP Page
package
Updated K&B 5 Errata - 4/16