That is the basic folder structure of a maven project. IntelliJ usually recognizes this and sets up sensical defaults for you.
If it didn't (or if it did but you modified them afterwards), you need to set up your java folder as the sources folder (i.e. the folder that contains the source code).
For this, you need to:
- Go to your project structure settings:
File > Project Structure - Select your project in the middle panel
- Select the 'sources' tab in the right panel
- Note from a comment (thanks @Line): In IntelliJ 2018.3.5, you "select 'modules' tab in left panel".
- Navigate to the
src/main/javafolder and select it - Mark it as
Sources
Repeat for test folder (mark as 'Tests'), resources (mark as 'Resources'), test-resources (mark as 'Test Resources'), etc.
Answer from blurfus on Stack OverflowThat is the basic folder structure of a maven project. IntelliJ usually recognizes this and sets up sensical defaults for you.
If it didn't (or if it did but you modified them afterwards), you need to set up your java folder as the sources folder (i.e. the folder that contains the source code).
For this, you need to:
- Go to your project structure settings:
File > Project Structure - Select your project in the middle panel
- Select the 'sources' tab in the right panel
- Note from a comment (thanks @Line): In IntelliJ 2018.3.5, you "select 'modules' tab in left panel".
- Navigate to the
src/main/javafolder and select it - Mark it as
Sources
Repeat for test folder (mark as 'Tests'), resources (mark as 'Resources'), test-resources (mark as 'Test Resources'), etc.
Your configuration in the IntelliJ's File > Project Structure page will be overridden by the project's pom.xml after every clean install. To prevent this, you need to configure the source directory in pom.xml as below:
<sourceDirectory>src/main/java</sourceDirectory>
java - How do you "Mavenize" a project using Intellij? - Stack Overflow
java - Intellij maven structure - Stack Overflow
Weird IntelliJ forgetting test roots problem
IntelliJ Idea with Maven Java project in WSL
Videos
For those that benefit from a visual, as I did:

Essentially, just right-click on the folder. In this example, it's called StackOverFlow and choose Add Framework Support and then check the Maven box. Please note, that this option only exists when you have created a class within the src folder.
Right-click on the module, select "Add framework support...", and check the "Maven" technology. (This also creates a pom.xml for you to modify.)
Either you can File > New Project > Maven Module (Intellij will ask if its using existing sources)
Or use File > Import Project > browse through the folder structure : Intellij auto detects the POM file as a valid project format
I think even if you right click on the project inside Intellij and add framework support > maven it will also import accordingly (not sure of this one )
In your folder, navigate to the pom.xml and Open With >> IntelliJ