Solved

working with packages

Posted on 1998-04-27
2
132 Views
Last Modified: 2010-04-16
In my Java-application I want to use packages because I have about 78 classes.
I want to devide them into 1 main package and 3 subpackages :
main : "ipstool" (which contains only the class with the main-method)
sub : "data", "exceptions" and "interface".
In every class of a certain package (all in one directory with the same name as the package..) I put
     package data;
in front of the import-statements.
Also I put there the other packages of my application, f.e. :
    import ipstool.exceptions.*;
    import java.awt.*;
I'm compiling from the directory that contains the "ipstool"-directory.

This doesn't compile however...
What am I doing wrong? Should I put something in the classpath or is it not necessary to import them as ipstool.exceptions.* but as exceptions.* or maybe something else ?
0
Comment
Question by:Jeppe041198
2 Comments
 

Author Comment

by:Jeppe041198
ID: 1219970
Edited text of question
0
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
ID: 1219971
From your description of the hierarchy, the "main" class would have to be in a subdirectory named ipstool, and the others in subdirectories below that. Or, to put it another way, if your classpath in effect is pointing to directory ipstool, you need to reorganize to have it point to one directory higher (ipstools parent), i.e. compile from the parent directory.

On the other hand, I have found that some Java environments (e.g. J++) are unhappy with Java programs that don't have a default package. The solution I would recommend is to make your "main" class be the default package, and the other three be package data, exceptions etc., in directories below.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now