Solved

working with packages

Posted on 1998-04-27
2
131 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
Comment Utility
Edited text of question
0
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

772 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

10 Experts available now in Live!

Get 1:1 Help Now