My Eclipse Java package is treated as a folder; can anyone suggest what's wrong?
-
if as a.b.c my package dir then a and a.b is used as package but not a.b.c – Gopal Feb 25 '11 at 13:51
-
Can you please post a screenshot of what you mean? We can't understand what you mean by your words alone unfortunatly. – adarshr Feb 25 '11 at 14:40
-
What solved my problem: After creating a new Java project, I had to import __into the src folder__ and not into the project folder. – aderchox Feb 06 '21 at 17:44
16 Answers
First, ensure that you're in the "Package Explorer" view of the Java Perspective.
Secondly, it needs to be made a Source Folder.
If you're in the Java Project, right click on the folder and select "Build Path" > "Use as Source Folder"
Something like what is shown here:
Observe that I am in Java perspective and see how the style of the folders "source" and "src" are different in appearance.
-
1i am in Project Explorer the parent folder of that folder is a source folder and no option like "Use as Source Folder" i am a new 2 java thanx 4 bearing me – Gopal Feb 25 '11 at 13:19
-
1
-
thnx 4 d image but my problem is some diff please see the comment i added to gilbert's answer – Gopal Feb 25 '11 at 14:46
Well, I actually think you might don't even need the answer anymore (almost two years later) but I will share anyway to document (just found a solution that others could use).
The problem: while searching some packages I accidentally clicked "Add to build path" in a package and after I ctrl+z, the package had became a folder.
The solution I found was on the .classpath. There was a line there with the name of the package I had just added to the build path (even after the Ctrl+Z). Delete that line and after refreshing the project your whole src folder will be turned into a normal folder.
Then right click your src, following this path: src > Build Path > Use as Source Folder.
This solved the problem, I just tested the result. Hope it helps.

- 2,094
- 2
- 24
- 37
-
This is what happened to me :P I deleted the .classpath file, removed src folder from the class path and then added it back again. – Gander7 Jan 03 '14 at 16:20
-
That also works in the opposite direction: Source -> Build Path -> Exclude changes a package into a folder – Johanna Jul 26 '18 at 13:06
go into your javabuildpath in properties and remove the folder from your Exclusions

- 91
- 1
- 1
Worst case, you'll have to delete the folder and recreate as a java package.
- Save the Java classes somewhere else in your Java project by refactoring
- Delete the folder and the underlying folder structure
- Create a Java package
- Move the Java classes back under the Java package by refactoring

- 50,182
- 6
- 67
- 111
-
1tried d same but it doesnt create the same named package( say A) but i can create package with name A1 also tried with refresh and resrt eclipse – Gopal Feb 25 '11 at 14:28
-
@Gopal Sharma: I'm guessing it's because you just deleted the folder, and not the underlying folder structure. Sorry, for not mentioning that you needed to do both in my answer. – Gilbert Le Blanc Feb 25 '11 at 14:30
-
i deleted the structure say i have com.a.b.c and com.a.x the com.a and com.a.x are treated as package but com.a.b and com.a.b.c are not treated as package so i tried to delete b and b.c but its not working – Gopal Feb 25 '11 at 14:36
-
@Gopal Sharma: Perhaps all you need to do now is a refresh of the Project Explorer. – Gilbert Le Blanc Feb 25 '11 at 14:39
-
-
-
May be you don't have any class whose package is a.b.c! Elipse hides empty packages. – adarshr Feb 25 '11 at 14:51
-
no it is not d case i will get d image in a min its on diff machine give me 2 mins – Gopal Feb 25 '11 at 14:53
-
@Gilbert and adarshr : thank you , it worked as changed workspace deleted parent to child all dir copy again – Gopal Feb 25 '11 at 15:03
-
No need of all this . just change the src folder path in .classpath – Vicky Kapadia Jul 09 '19 at 12:32
SIMPLE You are not in the Package Explorer View ( but in Navigator view) If not the above case, then create a new package under the project (staying in Package Explorer view) and move those classes to the newly created package. DONE.

- 181
- 2
- 3
Right click on Project > Configure > Convert to Faceted Form > Click on apply and OK
This one has worked for me.

- 57
- 1
- 11
i had the exact same Problem after i added the packege in java build path -> libraries -> add class folder...
Dont ask why i did this ^^ but to resolve the Problem i just had to go to Project->Properties->java build path->Source
And there it was in the Excluded part. Just remove it from the exclusion pattern and perhaps also from the libraries section.

- 33
- 7
This kind of issue occur due to missing of java and test folder in the web application
solution is :
Right click on the project folder -> properties -> java build path -> order and export and select the java and test folder and add or apply -> ok
then you should able to add the package in the java folder

- 133
- 1
- 2
- 8
No Need of delete, re-create etc.
Just modify .classpath file
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
........

- 6,025
- 2
- 24
- 30
I have faced the same issue and found the solution, as to add Java Nature
in .project
file of the current application.
Project natures are used in the Eclipse IDE in order to configure projects in the workspace. One project may have several project natures. The most popular project nature is org.eclipse.jdt.core.javanature, which is used to indicate that a project is a Java project.
Add org.eclipse.jdt.core.javanature
and its corresponding builder in the .project
file of an application as shown below:
<projectDescription>
<name>MyJavaApplication</name>
<comment></comment>
<projects></projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments></arguments>
</buildCommand>
<!-- ... -->
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<!-- ... -->
</natures>
</projectDescription>
Project view as Package structure:
Projects and its dependent modules as Hierarchical structure.
Package Explorer / View Menu / Package Presentation... / Hierarchical

- 9,250
- 2
- 69
- 74
Creating a package makes an older one instead.
I had the same problem, and I was not able to solve it. But I suggest this, as a possibility. After copying and moving classes between packages, any file, it could be that the classpath has different information and that it hasn't been updated.
After having read some comments above, I now am only using source folders instead the standard source Folder "src". Inserting packages in any new source folder always runs.

- 4,806
- 4
- 48
- 70

- 21
- 2
From the menu bar, select Navigate > Show In > Package Explorer.
This is what worked for me.

- 1,646
- 1
- 14
- 26
I had this on a maven project.
If it's a MAVEN project and this is a new module, you have to Import the module as maven project and it will work.
Right click -Import->Existing Maven Module...

- 71
- 3