HOWTO: Handling Packages with the Visual J++ Compiler

ID: Q162129


The information in this article applies to:
  • Microsoft Visual J++, versions 1.0, 1.1


SUMMARY

When the Visual J++ compiler, Jvc.exe, sees a package statement, it automatically creates the directory structure needed for the package declared. The .class files that define the classes in the package must be placed in this directory structure. By default, they are not placed in the correct directory. You must specify an output directory to tell the compiler where to place the .class files.


MORE INFORMATION

The .class files that define the classes in a package must be placed in a directory that matches the package name. For example if you were to define a package called "animals.dogs," the .class files that define the classes in this package must be located in the "animals\dogs" directory.

In order for the compiler to place the .class files in the correct directory, you must specify an output directory by clicking Settings on the Build menu. The Project Settings dialog box appears. Click the General tab if it is not already selected.

You will see two edit boxes, the second of which is labeled "Output Directory." The directory entered here is used as the root of the directory structure created for a package. If using the command line, Jvc.exe has a "/d" command line switch that lets you specify the output directory. You can also use a "." as the output directory and the compiler creates the necessary directories under the current structure and places the .class files there.

Thus if you entered c:\msdev\projects\packtest for the output directory, and you compiled a .class file with the package statement above, the following directory is created:


   c:\msdev\projects\packtest\animals\dogs 
The resulting class files are placed in this directory.

When compiling a class file that imports a package, the compiler searches the directories in the classpath for a directory that matches the name of the imported package. It then looks in that directory for the class files that define the class. If the class file cannot be found, the compiler gives J0049 (Undefined Name) and J0044 (Cannot find definition for class) errors.

Note that only the top-most directory in a package directory structure must be in a directory that's listed in the classpath. Continuing on with the animals.dogs sample, only the directory that contains the animals directory must be listed in the classpath (that is, c:\msdev\projects\packtest must be in the classpath). Once the compiler finds the animals directory it knows how to find the .class files in the subdirectories of animals. When searching for directories, Microsoft Developer's Studio (MSDEV) makes sure that the current project directory appears in the classpath.

When running an application or an applet, the Microsoft virtual machine similarly searches the classpath for the needed .class files. Since the root directory of the package hierarchy must be in the classpath, it's a good idea to have a central location for all packages. When you installed Visual J++, one was created for you:

   c:\<win-dir>\Java\Classes 
This directory is automatically included in the classpath. If you choose not to use a central repository, each time you create a package, you must add an additional entry to your classpath.


REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/

http://support.microsoft.com/support/java/

Additional query words:

Keywords : kbusage kbCommandLine kbGenInfo kbVJ kbVJ100 kbVJ110
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.