[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

working with packages

Posted on 1998-04-27
2
Medium Priority
?
139 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

649 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