HOWTO: Handling Packages with the Visual J++ Compiler

Last reviewed: January 29, 1998
Article 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 (VM) for Java 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 page on the Microsoft Technical Support site:

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

Keywords          : kbusage CmdLnUtils VJGenIss
Technology        : kbInetDev
Version           : 1.0 1.1
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.