Gradle building rest spring app can’t find main class
The error “Could not find or load main class” can occur when you’re trying to build a REST Spring app with Gradle. There are a few things you can check to try to fix this error: Gradle building rest spring app can’t find main class
- Make sure that the main class for your application is defined in the
build.gradlefile. The main class is typically the class that contains the
- Make sure that the main class is located in the
- Make sure that the main class has a public
- Make sure that the
main()method has the following signature:
public static void main(String args)
If you’ve checked all of these things and you’re still getting the error, you can try the following:
gradle cleanto clean the project’s build files.
gradle buildto rebuild the project.
- If you’re still getting the error, you can try asking for help on the Gradle forum or on Stack Overflow.
Here are some additional tips that may help you fix the “Could not find or load main class” error:
- Make sure that you’re using the correct version of Gradle.
- Make sure that you’re using the correct version of the Spring Boot starter dependency.
- Make sure that your project is configured correctly.
- Make sure that you’re not making any common mistakes.
I kept getting the follow error message. how to fix it.
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ‘:findMainClass‘. > org.gradle.api.tasks.SourceSetOutput.getClassesDir()Ljava/io/File;
id ‘org.springframework.boot’ version ‘2.1.7.RELEASE’
sourceCompatibility = 1.8
mainClass = “main.java.hello.Application”
Note that mainclass add your package name and main function name
both ./gradlew clean bootRun and ./gradlew clean build with java -jar build/libs/gs-rest-service-0.1.0.jar work well.