0

I totally understand this error message meaning, but how to fix it? Intellij doesn't allow me to click on the main application class.

org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:run (default-cli) on project XprojApplication: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.7.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>dev.house</groupId>
        <artifactId>xproj</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>15house</name>

        <description>Demo project for Spring Boot</description>

        <properties>
            <java.version>1.8</java.version>
        </properties>

        <packaging>war</packaging>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>

            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-servlet-api</artifactId>
                <version>8.0.36</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.9.4</version>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.9.4</version>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>2.9.4</version>
            </dependency>
        </dependencies>

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

                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
    <!--                    <archive>-->
    <!--                        <manifest>-->
    <!--                            <addClasspath>true</addClasspath>-->
    <!--                            <mainClass>dev.house.XprojApplication</mainClass>-->
    <!--                        </manifest>-->
    <!--                    </archive>-->
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>

            </plugins>
            <directory>/Users/poc/workspace/tw-real-estate-service-manager/webapps/15house</directory>
            <finalName>15house</finalName>
        </build>

    </project>

enter image description here

enter image description here

newBike
  • 14,385
  • 29
  • 109
  • 192
  • See https://stackoverflow.com/a/43319356/104891 and https://stackoverflow.com/a/42660624/104891. Try to delete `.idea` directory and reimport from `pom.xml`. What's the full path to the source root? Is it under `src/main/java`? – CrazyCoder Oct 20 '19 at 18:45

2 Answers2

0

It does not seem that your directories are marked properly.

Since you're using Maven, I assume you have the following structure.

enter image description here

Please ensure to mark the java directory as Sources Root by right-clicking on the folder and following the Mark Directory as submenu. You might want to do the same for the resources directory, marking it as Resources Root.

Matthew Formosa
  • 468
  • 3
  • 9
0

If you want bootable jar for spring boot, you can simply use below configuration in your pom.xml, you don't need maven-assembly-plugin

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <start-class>org.springframework.boot.loader.JarLauncher</start-class>
            </configuration>
        </execution>
    </executions>
</plugin>
Shailesh Chandra
  • 2,164
  • 2
  • 17
  • 25