IntelliJ - opening Java project with existing sources in folder that also serves as package


Letsay that existing Java source file(s) is in 'enums' folder. It also uses 'package enums'.
IntelliJ does not buy it. Is there a way to avoid the creation 'enums' package inside 'enums' folder to clear that error?


It is not recommended way to configure the project. 

A folder marked as sources root should be 1 level upper related to the package folder. 

So, it is better to open the folder "Courses" as a project, create directory "java" inside it and mark "java" as sources.

Also, IntelliJ IDEA compiles the code within the Sources Root. That is why, do not place configuration files (the .idea folder or its content and the .iml file) to this folder. 


Thanks for the info about the correct way. I am working with example code from online course that I downloaded from repository. At this level it is not a huge issue to correct the folder structure manually. I thought that perhaps I was missing something in settings when I was creating the project. 
Regarding second part of your reply - here is the current state of affairs after I added package 'enums' to folder 'enums'. Are you suggesting that '.idea' and 'enums.iml should be a level above - i.e. in 'v1ch05' folder?


Here is the structure I mean: 


You may share the repository you are speaking about, so I'll give a hint about its configuration. 


Please sign in to leave a comment.