gpt4 book ai didi

java - 即使我提到了 mainClass 属性并且它就在它的 Nose 底下,Spring-boot maven 插件也无法找到 mainClass

转载 作者:行者123 更新时间:2023-12-01 17:52:18 24 4
gpt4 key购买 nike

我有父项目“giftcard-service”,仅用于构建。所有代码都位于名为“giftcard-service-main”的模块中。我能够构建(干净安装)礼品卡服务,但无法部署/运行它,这是通过 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

模块(giftcard-service-main)的pom中明确提到了mainClass。这是模块的 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 时,您位于父项目的目录中。我认为您需要位于主类实际所属的子项目中。

关于java - 即使我提到了 mainClass 属性并且它就在它的 Nose 底下,Spring-boot maven 插件也无法找到 mainClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60775201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com