0

like mentioned in the title I have a Spring Boot project. Trying to start the project out of my IDE it says, that the main class can't be found.

I've found a relative equivalent question here: Spring Boot Program cannot find main class

But the solution doesn't do it for me (I already configured the main class in the pom.xml) like this:

<properties>
    <start-class>de.main.Main</start-class>
    <java.version>1.8</java.version>
</properties>

And this is what my main class looks like:

package de.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class Main extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Main.class);
    }

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

Additional to this an other project, which uses Spring Boot aswell, works totaly fine. And the pom.xml is configured the same way in both projects.

I use Spring Boot version 1.5.2 and eclipse oxygen.

The errormessage looks like this: "Fehler: Hauptklasse de.main.Main konnte nicht gefunden oder geladen werden" Roughly translated: "Error: main class de.main.Main can't be found or loaded"

My Project structure is like this:

Project
|--- Java Resources
|       |--- src
|       |     |----de.main
|       |
|       |--- WebContent
|
|--- pom.xml
Shisu
  • 1
  • 1
  • 5
  • 1
    can you add the error message? – oak Aug 22 '17 at 12:41
  • Its german, but sure: Fehler: Hauptklasse de.main.Main konnte nicht gefunden oder geladen werden – Shisu Aug 22 '17 at 12:43
  • Can you add the directory structure of the project? – oak Aug 22 '17 at 12:44
  • Do you really need to extend `SpringBootServletInitializer` and override the method? Would you mind trying to get rid of it and run it? – Pijotrek Aug 22 '17 at 12:48
  • @Pijotrek It worked for me in my other project - and getting rid of it doesn't work either. It's still the same problem. :( – Shisu Aug 22 '17 at 12:50
  • does it run from command line `mvn spring-boot:run` ? How do you run it from within your IDE ? What IDE is it? Also just noted that your project structure is not maven's default. Is your 'other' project structured in the same way? – diginoise Aug 22 '17 at 12:51
  • Yea it runs, it trows some errors - gonna check out why... The IDE is like mentioned in the question "eclipse oxygen" – Shisu Aug 22 '17 at 12:56
  • @diginoise found the reason for not starting - thanks! Next time I'll try to run it from cmd before asking dump questions... ^^' – Shisu Aug 22 '17 at 12:59

4 Answers4

1

Try to execute the current file like Run as -> Java Application. Then confirm it is running or not, then you can run the entire project at a time by Run as -> Spring Boot App. Try to post the directory structure of the project.

Arvind Katte
  • 995
  • 2
  • 10
  • 20
0

Please double-check that your Main class is under src/main/java/de/main/ directory.

aaguilera
  • 1,080
  • 10
  • 27
0

Found the reason by running the program via. cmd - some unnecessary dependencies caused trouble. Fixed the problem by deleting them.

Shisu
  • 1
  • 1
  • 5
0

I had the same problem. It worked for me after I did a maven build with goal set to test. (rightclick on project -> run as -> maven build ... -> when prompted what goal put test)

moriturus
  • 31
  • 3