Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding folder in eclipse in src directory without making it package

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).

like image 321
Tarun Kumar Avatar asked Nov 06 '11 05:11

Tarun Kumar


People also ask

How do I add a folder in Eclipse?

The Folder Wizard (File → New → Folder) can be used to create a new folder.

How do I create a folder within a folder in Eclipse?

I would suggest to add a resources folder at the top of your app tree so that your data and your classes are separated. But if you want to just add subpackage, do not create a new folder, just create a new package such as app. models. Folder1.

How do I mark a folder as source in Eclipse?

Right-click the folder, choose Build Path, then Use as Source Folder.

How do I create a src main resources folder?

Manually create src/main/resources path If the resources folder already isn't present in your maven project , you can just create the “resources” folder manually under src/main folder. Once the src/main/resources folder is created, we can add the resources in this path.


2 Answers

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.
like image 78
Mansoor Siddiqui Avatar answered Sep 22 '22 15:09

Mansoor Siddiqui


You need to go to Project -> Properties -> Java Build Path -> Source (tab).

Remove src from "Source Folders on Build Path"

Then add src/main as a source folder. If you already have org under main, then your packages should start with org as desired.

like image 20
Ray Toal Avatar answered Sep 20 '22 15:09

Ray Toal