The Intellij IDEA error for Maven project:
Error: Could not find or load main class root
can be result of several problems:
- need of import
- wrong configuration
- incomplete or incorect project import
- wrong out folder
Reimport Maven Project
The first thing you can try is to reimport your maven project by:
Show Maven window ( if not open )
- main menu
- View
- Tool Windows
- Maven Projects
- Press Reimport all maven projects - two blue arrows like like refresh button - the first button in Maven Projects toolbar.
Incomplete import of maven project
If you have problem during the import of the project or maven project is imported without providing information that is a maven project then the error will occur during execution of your code. In order to solve this problem:
- delete the broken project
- reimport the project
- File - or Import Project in case of Intellij without open project.
- New
- Project from Existing Sources
- select the project folder
- in Import Project wizard
- select Maven
- select the project's SDK
- set project name and location
- Click Finish.
Rebuild project or invalidate cache
In case of broken configuration you can try to rebuild your project or to invalidate your cache and restart.
invalidate and restart
- main menu
- File
- Invalidate Caches/Restart
- Invalidate and Restart
the caches will be invalidated and rebuilt on the next start.
Rebuild project
Due to some problems classes in IntelliJ could be older versions or missing so this will force IntelliJ to clean and rebuild classes information
- main menu
- Build
- Rebuild Project
Change running configuration
In case of problem due to running configuration you can try:
- main menu
- Run
- Edit configuration
- Remove Configuration - select the broken configuration
- Add New Configuration - select your information as name, SDK and folders
Change output folder
In case of wrong Project compiler folder you can try:
- main menu
- File
- Project Structure or - CTRL+ALT+SHIFT+S
- Project compiler output
- set your path:
- for linux - /home/user/IdeaProjects/ProjectName/out
- fow windows - C:/user/IdeaProjects/ProjectName/out
Check maven settings
Check VM options
- main menu
- File
- Settings or - CTRL+ALT+S
- Build, Execution, Deployment
- Build Tools
- Maven
- Runner
- check VM Options
import maven project automatically
- main menu
- File
- Settings or - CTRL+ALT+S
- Maven
- Importing
- check Import Maven projects automatically