【问题标题】:"Spring Boot Project" Error: Could not find or load main class fyp.fms.FleetManagementSystemApplication“Spring Boot Project”错误:无法找到或加载主类 fyp.fms.FleetManagementSystemApplication
【发布时间】:2020-10-10 11:25:41
【问题描述】:

我已经浏览了堆栈溢出的所有可用文章。但是我的问题没有解决。我有一个可以正常工作的 java 8,它在我的所有应用程序中都可以在 eclipse 中正常工作,而且我也尝试使用 cmd 运行。这意味着类路径,环境变量等,一切正常。现在我想创建一个 Spring Boot 项目,所以当我使用 Run As Java Application 和 Spring Boot App 运行一个 Spring Boot 项目时,它会给出这个错误“错误:找不到或加载主类 package.classname”这是屏幕截图:

注意:我已经尝试了几乎所有的事情,比如清理项目、检查环境变量、更新 Eclipse 等。这个问题只存在于 Spring Boot 应用程序中。所有其他 Java 应用程序都可以正常工作。

这是我的 pom.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>

4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.1.发布 fyp fms 0.0.1-快照 车队管理系统 Spring Boot 上的车队管理系统。最后一年的项目。

<properties>
    <java.version>1.8</java.version>
    <start-class>fyp.fms.FleetManagementSystemApplication</start-class>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</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-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

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

【问题讨论】:

    标签: java spring-boot error-handling runtime-error runtimeexception


    【解决方案1】:
    1. 在 pom.xml 中添加以下属性

       <properties>
           <start-class>fyp.fms.FleetManagementSystemApplication</start-class>
       </properties>
      
    2. 如果您的 pom 中没有此构建插件,请添加它

       <build>
              <plugins>
               <plugin>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
                  <configuration>
                      <executable>true</executable>
                  </configuration>
              </plugin>
              </plugins>
      </build>
    
    1. 运行mvn clean install
    2. 使用mvn springboot:run 运行应用程序

    您可以尝试以下步骤吗:

    右键单击您的项目。选择“运行方式”->“Maven 构建...”。然后在“目标”字段中,输入“spring-boot:run”。应用并运行。

    【讨论】:

    • 我已经完成了这些步骤,并且在您回答之后,但问题仍然相同。
    • 我已经上传了我的 xml 文件。
    • @Asmat 使用上述更新的解决方法,如果您仍有问题,请告诉我。
    • 是的,我已经应用了您的步骤,但问题仍然存在。
    • 你能重新格式化你上面分享的 Pom.xml 文件吗? @Asmat
    猜你喜欢
    • 1970-01-01
    • 2018-12-19
    • 2021-12-18
    • 2016-04-20
    • 2016-06-12
    • 2016-03-16
    • 2016-01-03
    • 1970-01-01
    相关资源
    最近更新 更多