?
Solved

working with packages

Posted on 1998-04-27
2
Medium Priority
?
138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

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

Accepted Solution

by:
imladris earned 150 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

801 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