Unable to find a suitable main class, please add a 'mainClass' property, Spring boot

I believe the issue I was having is similar to yours. I have a multi module app using Spring Boot and only one Application.java (with main method).

I was struggling with it trying to start it up using Maven and I got the same result as yours (unable to find a suitable main class).

I spent several hours trying and changing stuff and after adding the property mainClass to the pom, it couldn't find it.

Then I decided to run the project not from the root project but from the project where the Application class is.

By doing this I was able to start up Spring Boot and everything works like a charm.

Updated

If you want to package the whole thing to be executed with java -jar file you can run the command below from the root project:

mvn clean package spring-boot:repackage 

Don't forget to add the spring-boot-maven-plugin to your pom.


In my case i had in main pom:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>

whitch includes plugin spring-boot-maven-plugin

I had to add to main pom to skip it:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <skip>true</skip>
        </configuration>
    </plugin>

and then in module with ma Application class:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <skip>false</skip>
        </configuration>
    </plugin>

Remove the maven build plugin code from the parent pom, which will be similar to the below, the below snippet should be only in the sub module pom where you have main class for spring boot application:

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>