user1796942
user1796942

Reputation: 3518

How do I organize my Java Eclipse project so that the user then only needs to do one import?

How do I organize my Java Eclipse project so that the user then only needs to do one import?

I am working on a graphics library and I have various package in it like graphics.A, graphics.B, etc. but when I give this library to the user I want him to be able to use it just by saying import graphics for example. I am not sure how to do that. The way I have it now he would have to do import graphics.A., import graphics.B., etc.

Thanks

Upvotes: 3

Views: 102

Answers (2)

Naikrovek
Naikrovek

Reputation: 171

Well, tooling should take care of managing the imports. I'm not sure why having a single import is of any importance, but I can't know your motivations, so I'll just accept it.

  • Put all your classes in a single package. (not recommended at all.)
  • Create a broker class that, once instantiated, reaches into the package hierarchy and instantiates everything for you and returns Object instances, or some root type of your design. (not recommended at all.)
  • Assume your developers have tooling which can manage the imports for them and don't worry about it. (Recommended.)

Upvotes: 2

Nikolay Kuznetsov
Nikolay Kuznetsov

Reputation: 9579

Importing all subpackages with single line is impossible in Java.

import graphics.*;

would import only classes in graphics, graphics.A and graphics.B would not be imported, if A and B are subpackages.

So either put all your classes in one subpackage, or user would have to import more than once like

import graphics.A.*;
import graphics.B.*;

Upvotes: 5

Related Questions