Xyzk
Xyzk

Reputation: 1332

Can I create folder inside package in eclipse?

I have project, with source folder "app", inside this package I have package "models". Can I create folder or any other kind of subdirectory within this package? So that eventually I would have something like

-app
   -models
       -Folder1
           -file1
           -file2
       -Folder2
           -file3
           -file4

When I try to force creating folder inside (by clicking new->other->folder), I cannot add anything to it.

Upvotes: 5

Views: 18046

Answers (4)

Cameron Hudson
Cameron Hudson

Reputation: 3931

The default package representation is Flat. You want to change it to Hierarchical.

enter image description here

Upvotes: 1

Julien Bourdon
Julien Bourdon

Reputation: 1723

Packages and folders are slightly different conceptually.

You generally group your classes that deal with the same functionality in the same package. For example the core classes, the model of your app can be in com.example.myapp.core and the ui classes in com.example.myapp.ui .These packages are represented on the disk by a folder structure.

In my opinion, you should not change this package structure to add files that are not Java classes. 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.file1 and you will get the structure you want.

You can refer to this question to know more about the packaging conventions: Are there best practices for (Java) package organisation?

Upvotes: 1

Scary Wombat
Scary Wombat

Reputation: 44813

a folder in a package is just another package, so you want new->package then type in app.models.folder1

Upvotes: 2

cmd
cmd

Reputation: 11841

Creating a folder within a package simply creates a new package

e.g. The folder structure

 - app
    - models

equates to package app.models

Adding a new folder, Folder1 to this structure

e.g.

-app
  -models
    -Folder1

equates to the package app.models.Folder1

Upvotes: 3

Related Questions