“Spring Boot 项目”错误:无法找到或加载主类 fyp.fms.FleetManagementSystemApplication

问题描述 投票:0回答:1

我已经浏览了 stack over flow 中和输出的所有可用文章。但我的问题没有解决。我有一个工作java 8,它在 eclipse 中的所有应用程序上运行良好,而且我也尝试使用 cmd 运行。这意味着类路径、环境变量等,一切正常。现在我想创建一个 Spring Boot 项目,因此当我使用 Run As Java 应用程序和 Spring Boot 应用程序运行 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-父级 2.3.1.发布 五年计划 调频管理系统 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个回答
0
投票
  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
  3. 运行应用程序

您可以尝试以下步骤吗:

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

© www.soinside.com 2019 - 2024. All rights reserved.