File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

Packages, directory structures, javac -d and CLASSPATH

Sergey Gorovoy
Greenhorn

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 Test.java
package testPackage;
public class Test {...}
//Second src file saved as TestingTest.java
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,
Sergey
Allen Thomas
Greenhorn

Joined: Jul 02, 2002
Posts: 29
Hi,
I found this url: http://mindprod.com/classpath.html
very helpful in my understanding of classpaths. I hope it helps you.
Allen
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Packages, directory structures, javac -d and CLASSPATH
 
Similar Threads
Not being able to compile Chapter 1 Servlet on page 30
Compiling a Servlet
A pain in the ......Please help?
compiling command: servlet-api.jar:classes: . ?
Package problem in walkthrough