Saurabh Patil
Saurabh Patil

Reputation: 4462

Spring-boot maven plugin is not able to find the mainClass even when I've mentioned the mainClass property and it's right there under it's nose

I have the parent project "giftcard-service" which I use only to build. All the code is in the module which is named "giftcard-service-main". I'm able to build (clean install) giftcard-service but not able to deploy/run it, which we do by mvn spring-boot:run command.

Since this is an enterprise/company project I would restrict some information for obvious reasons.

This is the error I get on console.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] giftcard-service                                                   [pom]
[INFO] giftcard-service - Main                                            [jar]
[INFO] 
[INFO] -------------< com.tc.pt:giftcard-service >-------------
[INFO] Building giftcard-service 1.0.0.1                                  [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) > test-compile @ giftcard-service >>>
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce) @ giftcard-service ---
[INFO] 
[INFO] --- git-commit-id-plugin:2.1.12:revision (default) @ giftcard-service ---
[info] isPomProject is true and skipPoms is true, return
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) < test-compile @ giftcard-service <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) @ giftcard-service ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for giftcard-service 1.0.0.1:
[INFO] 
[INFO] giftcard-service ................................... FAILURE [  2.137 s]
[INFO] giftcard-service - Main ............................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.323 s
[INFO] Finished at: 2020-03-19T18:53:35-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) on project giftcard-service: Unable to find a suitable main class, please add a 'mainClass' property -> [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/MojoExecutionException

The mainClass is clearly mentioned in the pom of module (giftcard-service-main). Here's the pom of the module:

   <?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>giftcard-service-main</artifactId>
    <packaging>jar</packaging>
    <name>giftcard-service - Main</name>
    <description>giftcard-service Web Service Implementation</description>

    <parent>
        <groupId>com.tc.pm</groupId>
        <artifactId>giftcard-service</artifactId>
        <version>1.0.0.1</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <dbcp2.version>2.1.1</dbcp2.version>
        <mysql-client.version>6.0.3</mysql-client.version>
        <spring-retry.version>1.2.4.RELEASE</spring-retry.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.tc.springboot</groupId>
            <artifactId>springboot-foundation-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.tc.springboot</groupId>
            <artifactId>springboot-foundation-starter-management</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>com.tc.fluentd.logging</groupId>
            <artifactId>fluentd-logback</artifactId>
        </dependency>
        <!--
        <dependency>
            <groupId>com.tc.hawtio</groupId>
            <artifactId>hawtio-extension-spring-boot</artifactId>
        </dependency>
        <dependency>
            <groupId>net.bull.javamelody</groupId>
            <artifactId>javamelody-spring-boot-starter</artifactId>
        </dependency>
        -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.tc.springboot</groupId>
            <artifactId>springboot-foundation-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>${dbcp2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
            <version>${spring-retry.version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-client.version}</version>
        </dependency>

        <dependency>
            <groupId>com.tc.pm</groupId>
            <artifactId>pm-pt-dao</artifactId>
            <version>${pm-pt-dao.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.tc.pm</groupId>
            <artifactId>fw-client</artifactId>
            <version>${fw-client.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.tc.pm</groupId>
            <artifactId>pm-common-components</artifactId>
            <version>${pm-common-components.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.tc.pm</groupId>
                    <artifactId>pm-pt-interface</artifactId>
                </exclusion>
            </exclusions>
        </dependency> 
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources/</directory>
                <excludes>
                    <exclude>conf/**</exclude>
                </excludes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources/</directory>
                <includes>
                    <include>static/version.html</include>
                    <include>template/index.html</include>
                    <include>banner.txt</include>
                    <include>application.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <dataFile>${jacoco.out.path}${jacoco.out.file}</dataFile>
                            <rules>
                                <rule implementation="org.jacoco.maven.RuleConfiguration">
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit implementation="org.jacoco.report.check.Limit">
                                            <counter>BRANCH</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>${min.branch.coverage}</minimum>
                                        </limit>
                                        <limit implementation="org.jacoco.report.check.Limit">
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>${min.branch.coverage}</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- Sets the VM argument line used when unit tests are run. -->
                    <argLine>${surefireArgLine}</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.tc.pm.giftcard.Application</mainClass>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}.original</file>
                                    <classifier>original</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

I'm using

Scenario (you should probably know) -- So I'm trying to set this project on a new machine, installing everything right from JDK, eclipse, maven etc on this machine. This should work as it works for my team mates.

The mainClass is right there, not sure why this is failing! Any help is highly appreciated, blocked on this since morning :(

Thanks!

Upvotes: 0

Views: 2019

Answers (1)

DaveyDaveDave
DaveyDaveDave

Reputation: 10562

Near the start of the Maven output, I see this line:

[INFO] Building giftcard-service 1.0.0.1

I'm not sure, but suspect this means you're in the parent project's directory when you're trying to execute mvn spring-boot:run. I think you need to be in the sub-project, where the main class actually belongs.

Upvotes: 1

Related Questions