[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) on project SpringBoot: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage failed: Unable to find main class

By Yashwant Chavan, Views 32, Last updated on 14-Apr-2019

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) on project SpringBoot: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage failed: Unable to find main class

tags spring spring-boot

Maven Command

While building Spring boot application. I am getting, Unable to find main class error. Here is complete stack trace.

mvn clean package spring-boot:repackage 

Error

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringBoot 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ SpringBoot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ SpringBoot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\java-projects\SpringBoot\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ SpringBoot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ SpringBoot ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ SpringBoot ---
[INFO] 
[INFO] --- maven-war-plugin:3.1.0:war (default-war) @ SpringBoot ---
[INFO] Packaging webapp
[INFO] Assembling webapp [SpringBoot] in [C:\java-projects\SpringBoot\target\SpringBoot-1.0]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\java-projects\SpringBoot\src\main\webapp]
[INFO] Webapp assembled in [1112 msecs]
[INFO] Building war: C:\java-projects\SpringBoot\target\SpringBoot-1.0.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ SpringBoot ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.754s
[INFO] Finished at: Fri Apr 12 11:06:02 IST 2019
[INFO] Final Memory: 25M/207M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) on project SpringBoot: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage failed: Unable to find main class -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Solution

To resolve this issue, just add class which denotes with @SpringBootApplication annotation. Our main method delegates to Spring Boot's SpringApplication class by calling run method. SpringApplication class bootstraps our application, starting Spring which in turn starts the auto-configured Tomcat web server.

package com.technicalkeeda.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

Execute maven command mvn clean package spring-boot:repackage

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringBoot 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ SpringBoot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ SpringBoot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\java-projects\SpringBoot\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ SpringBoot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ SpringBoot ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ SpringBoot ---
[INFO] 
[INFO] --- maven-war-plugin:3.1.0:war (default-war) @ SpringBoot ---
[INFO] Packaging webapp
[INFO] Assembling webapp [SpringBoot] in [C:\java-projects\SpringBoot\target\SpringBoot-1.0]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\java-projects\SpringBoot\src\main\webapp]
[INFO] Webapp assembled in [1082 msecs]
[INFO] Building war: C:\java-projects\SpringBoot\target\SpringBoot-1.0.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ SpringBoot ---
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ SpringBoot ---
[INFO] Installing C:\java-projects\SpringBoot\target\SpringBoot-1.0.war to C:\Users\Yashwant\.m2\repository\com\technicalkeeda\SpringBoot\1.0\SpringBoot-1.0.war
[INFO] Installing C:\java-projects\SpringBoot\pom.xml to C:\Users\Yashwant\.m2\repository\com\technicalkeeda\SpringBoot\1.0\SpringBoot-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.588s
[INFO] Finished at: Fri Apr 12 11:39:31 IST 2019
[INFO] Final Memory: 26M/186M
[INFO] ------------------------------------------------------------------------
Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]