Adding folder in eclipse in src directory without making it package

Tarun Kumar picture Tarun Kumar · Nov 6, 2011 · Viewed 67.9k times · Source

While creating one folder in src directory in one project in eclipse, it makes that folder a package. Is there any way to avoid this folder from automatically being a package? e.g., I add main folder in src directory. I don't want it to become a package. How can I do this?

Suppose I add folders in this manner: src/main/org/apache. I don't want main.org.apache to be a package, instead, I want the packaging to start from org. (i.e., org.apache).

Answer

Mansoor Siddiqui picture Mansoor Siddiqui · Nov 6, 2011

Eclipse forces you distinguish between source directories and ordinary folders. Any subdirectories in a source folder will be considered a package.

In your case, you can create an ordinary folder outside of src/ to prevent the subdirectories from being interpreted as packages.

Alternatively, you can modify the project properties to have src/ be considered an ordinary directory, and put a source directory within it.

You can manage which directories in a project are considered source directories by:

  1. Right-clicking your project, then click Properties.
  2. In the left pane, click Java Build Path. In the right pane, select the Source tab.
  3. Here you can add/edit/remove source folders.