簡體   English   中英

Spring-boot Maven 插件無法找到 mainClass 即使我已經提到了 mainClass 屬性並且它就在它的鼻子下面

[英]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

我有我只用於構建的父項目“giftcard-service”。 所有代碼都在名為“giftcard-service-main”的模塊中。 我能夠構建(全新clean install )禮品卡服務,但無法部署/運行它,我們通過mvn spring-boot:run命令來完成。

由於這是一個企業/公司項目,我會出於明顯的原因限制一些信息。

這是我在控制台上得到的錯誤。

[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

mainClass在模塊(giftcard-service-main)的pom中有明確的提及。 這是模塊的pom:

   <?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>

我正在使用

  • 最新 Eclipse (2019-12 (4.14.0))
  • Maven 3.6.3
  • spring-boot-maven-plugin 2.1.3.RELEASE
  • 打開JDK 12 Windows 10(新安裝)

場景(你可能應該知道)——所以我試圖在一台新機器上設置這個項目,在這台機器上安裝來自 JDK、eclipse、maven 等的所有東西。 這應該對我的隊友有效。

mainClass 就在那里,不知道為什么會失敗! 任何幫助都受到高度贊賞,從早上開始就被阻止了:(

謝謝!

在 Maven 輸出的開頭附近,我看到了這一行:

[INFO] Building giftcard-service 1.0.0.1

我不確定,但懷疑這意味着當您嘗試執行mvn spring-boot:run時您在父項目的目錄中。 我認為您需要在主類實際所屬的子項目中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM