Search code examples
javaeclipseimportfilesystemsproject-organization

Project file organization in Eclipse


I'm just getting to know Eclipse, and I'm trying to familiarize myself with how I should handle file organization and importing classes. This is a screenshot of the Package Explorer for reference:

Project Explorer

I've got two projects: "CashierSimulation" is a simulation of a cashier (go figure), and "BeanJuice" is a text-based game about coffee. Each of these use some or all of the generic classes that I made, which are located in the "GenericClasses" project file.

Originally, all of the files in all three project files were located in the same project file "BeanJuice", but I decided to separate the simulation files from the game files, and I moved the generic classes to their own project file because they aren't specific to the game.

I've figured out how to import the generic classes to the different project files as needed by referencing this post:

Import a custom class in Java

In addition to importing the classes using:

import package.myclass;

each project's properties file had to be updated to include "GenericClasses" in the build path.

Doing all of this worked and got my programs running, but I'm wondering if this is the "correct" way of doing all of this.

  • Is there an easier way that this could be done?
  • Should generic classes be stored in their own project file like this, or is there another way that it is more commonly done?
  • Should the packages inside each project file be renamed, or is this only necessary when you're planning on importing something from that package?

Any tips or tricks would be appreciated.


Solution

    1. You may also want to have a look at maven and how to create "maven" modules in eclipse (or other IDEs); especially if you are authoring some sort of libraries for general consumption.
    2. There isn't any general rule on putting generic classes in their own project. They simply need to be logically grouped - into their own packages and/or projects.
    3. Also, instead of manually renaming the packages etc..., you may use 'refactor' (move etc...) - IDE will do the rest.