This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
packages and files
Posted by Joan Friedman on May 25, 2000 at 9:14 AM
Your .java and .class files need to be in a directory structure that matches the packages they are in.
If 'derived.java' and 'demo.java' are in the default package (no package specified), and they are in
c:\test, then 'base.java' in package 'MyPack' has to be in c:\test\MyPack. The class files can be in
the same directories as the source files, or in another - for example, you could put the class
files in c:\test\classes. If you do, then 'base.class' will be
> I have small program which has a base class (class name: "base"), with a defualt constructor wich just prints base's member variable. The scope of this class and the constructor is "Public". I create this in a package "MyPack" and save in a file called base.java.
> I have a different file called derived.java which imports the package "MyPack" and it derives from class base. In this class i just print the value of base class value.
> I have a third file called "demo.java" which has the main method creating an object of the derived class.
> Now i store these 3 files in a directory c:\test\*.java
> I want to compile these 3 files and put the resulting .class files in the directory c:\test\MyPack.
> The problem i'm facing is : the first file base.java gets compiled and puts the base.class file in
> c:\test\MyPack\base.class. Now while compiling derived.java, it gives a error that the "base class is not found".
> i compiled like :c:\test\> javac -d c:\test\MyPack\ derived.java
> I tried with -classpath option also. It's still giving the same error. How to compile this and what could be reason for the error?