tags:

views:

390

answers:

5

Hello! Is it possible in Eclipse to create a separate Folder in a package? When select "new --> folder", my eclipse version always creates a package. But i want the new folder to be in the old package.

How can this be achieved?

Thanks in advance...

Patrick

+3  A: 
jjnguy
+1  A: 

You need to exclude the folder from the source path

GClaramunt
+1  A: 

In a source folder, all 'new' folders will be considered a new package. It's part of the Java spec that makes all folders from a root to be part of the package structure.

Kelly French
+1  A: 

As others have said, this is standard java behaviour and shouldn't really be worked around. You are probably better off creating another folder outside of the source folder.

However there is a way to do it in Eclipse, be warned that this might come back to haunt you if you later try to build outside Eclipse as other tools won't honour these settings.

You can exclude a folder from the source path by opening the project properties.

Selecting Java Build Path->Source Select the appropriate source folder and select the Excluded: child item Hit the Edit... button. Select the Add button next to the Exclusion patterns: pane Add your folder and Finish/OK back to the editor.

The matching resources will now be excluded from compilation within Eclipse. It will still appear as a package in the editor though.

Rich Seller
A: 

You want to create a new child package (bar) of the existing package. (com.foo)

Select new package and name it "com.foo.bar". Eclipse will correctly place it under com.foo.

FYI: Folders under any "source" folder are shown as packages. There is no physical difference except that they appear on the build path. As shown elsewhere you can exclude them but it's easier to just not put them under /src/... to begin with.

Chris Nava