Home > Back-end >  intermittent "No main class is found." errors from the Spring Boot Dashboard in visual stu
intermittent "No main class is found." errors from the Spring Boot Dashboard in visual stu

Time:12-01

I'm just getting started with Java and I prefer Visual Studio Code over Eclipse. I downloaded the popular Java extensions for it including the Spring Boot tools (including Dashboard). When I switch to the Spring Boot Dashboard and click the Run or Debug button, I sometimes get a "No main class is found." popup error message and nothing starts. If I restart vscode, sometimes it works with the project that previously didn't, but another project that worked in the past is now throwing this error. It doesn't always happen with the same project. It all seems very random about when this exception is thrown. I have about 6 microservices projects (Eureka discovery, gateway, config server, different business logic), and it's hard to get all 6 to start. I can reliably start them with the default Run and Debug option or via jars - and they all always work.

All the projects were created with Spring Initializr and they do indeed have a main function:

package ...;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class ...ApiGatewayApplication {

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

CodePudding user response:

This is a known issue with Vscode :

https://github.com/microsoft/vscode-java-debug/issues/606

And the workaround solution is, install Code Runner Extension :

https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

then, click Run icon in the upper right-hand corner,press F1, Clean the java language server workspace.

  • Related