8

I am trying to create a run configuration for a spring boot app, but Intellij can't find the main class of the spring boot app (Usually it is automatically populated). I tried adding the class by searching the project structure, but Intellij won't let me add that application's main file to 'Main class' of the configuration. How can I make Intellij detect the class?

Project Directory:

rootfolder
   > springBootBackEnd
   > angularUI

I have the module set to 'rootfolder' and the content root is the rootfolder

5
  • do you select the related folder as a source root? Dec 13, 2017 at 14:46
  • Idea will also check that the class has a valid main method. It also needs to be within the selected module. Dec 13, 2017 at 14:51
  • @Generic yes, I set the parent folder of the spring boot application as the content root.
    – matchi
    Dec 13, 2017 at 14:53
  • Do you have the Spring Boot plugin installed? Also check if you have the classpath of modules set as your project in Run Configuration.
    – Rakesh
    Dec 13, 2017 at 14:53
  • @Rakesh I do have SpingBoot plugin, but I do not have classpath of modules set. It does not let me set the classpath of modules - there are no options in the dropdown.
    – matchi
    Dec 13, 2017 at 14:57

9 Answers 9

32

Problem may be that you have badly configured IDEA project files.

Close IDEA, delete all .idea files and reimport project.

2
  • Solved the problem like a charm... :) Dec 30, 2020 at 15:43
  • be aware that ths also deletes all your run configurations, db connections etc. maybe better go into the folder .idea and delete the files that are not in the folders runConfigurations, dbConnections, shelf, etc. Jan 5 at 13:19
7

The same issue occured to me. In my case, it was the project JDK that was not set. The module JDK was set, but not the project one.

Go to File > Project Structure > Project > Project SDK to solve the issue.

2
4

I had similar problem. Try File -> Project Structure -> Modules in the middle column click on your project's name and in the right make sure that src folder is marked as Source Folders (blue folder icon and blue text on the right).

1
  • 2
    When I tried this on spring boot project, IntelliJ didn't fix itself and was unable to locate the spring boot main class Dec 30, 2020 at 15:43
2

I had the similar issue. But I solved by going to File -> Project Structure, then select Modules and delete the content on the right pane(Sources tab). After save it, I was able to add the Spring Boot configuration as usual. Thanks @AlminaS for the lead.

1

It could be a bad plugin: check your IDEA log through the menu Help -> Show log in... and if your log is full of errors, try disabling that plugin.

The other answers here are correct too, but many folks have posted a problem with "X" plugin cause further plugins to fail to load (I needed spring boot plugin). I've read about various plugin issues including docker, python, php, etc.. This was the case for me, but in my case it was a "toml" plug-in. I can't be sure when I installed/enabled it, but I certainly didn't need it and I found out by reading the log. The other answers here are valid but if someone suggested to just check the log it'd have saved me a couple hours...

1

In my case, the problem was the version of IntelliJ. For Community Edition the Spring Boot is not present on the Add new configurations list from Run/Debug Configuration.

I used Ultimate version and all things are works as expected.

Add new configurations image from Ultimate Edition

0

What solved the issue for me is to mark the resources folder as Resources Root.

Right click on src/main/resources -> mark directory as -> Resources Root.

This was in addition to that that src/main/kotlin was already marked at Sources Root.

0

Java SDK and Tomcat server versions must be compatible.

-1

I had the same issue. I solved it by going to "src->main->java" and then right-click on java and select the option "mark directory as" source root. Then rebuild the pom.xml file to solve the issue..

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.