This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Packages, directory structures, javac -d and CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Packages, directory structures, javac -d and CLASSPATH" Watch "Packages, directory structures, javac -d and CLASSPATH" New topic

Packages, directory structures, javac -d and CLASSPATH

Sergey Gorovoy

Joined: Jul 28, 2001
Posts: 3
OK, after doing some major brainstorming, researching, reading and testing, I'd like to get a confirmation on whether I'm using all of the things in the Subject line correctly (I'm running Windows 2000, BTW):
2 source files:
//First src file saved as
package testPackage;
public class Test {...}
//Second src file saved as
import testPackage.*;
public class TestingTest extends Test {...}
Directory structure: C:\Java\Sources for, well, *.java sources. C:\Java\Objects for *.class files.
The compiling is done from the C:\Java\Sources directory by issuing javac -d C:\Java\Objects *.java, which creates TestingTest.class in the CLASSPATH directory, then testPackage directory in the CLASSPATH directory, and lastly the Test.class in the newly created directory.
To call the TestingTest I issue java TestingTest from anywhere (that's where CLASSPATH comes in handy I guess), and to call Test I issue java testPackage.Test.
Ok, all is working fine, however, here are some things that I'm still not quite clear about:
Somehow I believed that one needs to specify just the root directory (in my case C:\Java) in the CLASSPATH. However, it doesn't seem to work, but adding \Objects\ fixes it... Another understanding (however possibly wrong) was that javac -d and CLASSPATH were related, i.e. I wouldn't need to specify the whole path, just the last directory for compiling. So instead of the example above the setup should have been C:\Java for CLASSPATH, then issue javac -d \Objects\ *.java to compile from the sources directory. That doesn't work as well. So what is the correct setup then and is there a relationship between CLASSPATH variable and javac -d?
Thanx for any clarification,
Allen Thomas

Joined: Jul 02, 2002
Posts: 29
I found this url:
very helpful in my understanding of classpaths. I hope it helps you.
I agree. Here's the link:
subject: Packages, directory structures, javac -d and CLASSPATH
It's not a secret anymore!