当前位置: 首页 > 知识库问答 >
问题:

Maven验证Spring Boot应用程序类ClassNotFoundException

燕朝明
2023-03-14

当我尝试为Java Spring Boot项目运行verify lifecycle of Maven时,我得到了一个NoClassDefoundErr。它使用mvn spring-boot:run进行很好的编译,但当我运行mvn clean verify时,它会失败,因此:

$mvn clean verify -Dsurefire.skip=true -X
...
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.209 sec <<< FAILURE! - in com.fitforger.FitForgerBackendApplicationTests
    initializationError(com.fitforger.FitForgerBackendApplicationTests)  Time elapsed: 0.005 sec  <<< ERROR!
    java.lang.NoClassDefFoundError: com/fitforger/model/GymRat
    Caused by: java.lang.ClassNotFoundException: com.fitforger.model.GymRat
+----src
     +----main
     |    +----java
     |    |    +----com
     |    |         +----fitforger
     |    |              +----controller
     |    |              |    +----GymRatController.java
     |    |              |    +----WorkoutNodeController.java
     |    |              +----dao
     |    |              |    +----GymRatDAO.java
     |    |              +----exception
     |    |              |    +----GymRatCreationFailure.java
     |    |              |    +----GymRatExistsException.java
     |    |              |    +----GymRatNotFound.java
     |    |              |    +----GymRatUpdateFailure.java
     |    |              +----FitForgerBackendApplication.java
     |    |              +----model
     |    |              |    +----FitForgerModel.java
     |    |              |    +----GymRat.java
     |    |              |    +----WorkoutAttribute.java
     |    |              |    +----WorkoutNode.java
     |    |              |    +----WorkoutNodeTypes.java
     |    |              +----repository
     |    |                   +----CouchbaseRepository.java
     |    |                   +----FitForgerRepository.java
     |    +----resources
     |         +----application.properties
     +----test
          +----java
          |    +----com
          |         +----fitforger
          |              +----FitForgerBackendApplicationTests.java
          |              +----GymRatSteps.java
          |              +----repository
          |                   +----CouchbaseRepositoryTest.java
          +----resources
               +----com
                    +----fitforger
                         +----GymRat.feature
<build>
    <resources>
        <resource>
            <directory>resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
            <includes>
                <include>application.properties</include>
            </includes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.19.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.1.RELEASE</version>
        </plugin>
    </plugins>

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.5.1.RELEASE</version>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <excludes>
                        <exclude>com.fitforger.FitForgerBackendApplicationTests</exclude>
                    </excludes>
                    <skip>${surefire.skip}</skip>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>com.fitforger.FitForgerBackendApplicationTests</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build

共有1个答案

蒋弘致
2023-03-14

通过执行以下操作解决了OP问题,

这看起来和你面临的差不多。你能试着用吗

<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
   <configuration>
        <classifier>exec</classifier>
   </configuration>
 </plugin>
 类似资料:
  • 我正在使用Spring引导应用程序连接MongoDB实例。我们已在MongoDB上启用了以下角色的身份验证 角色:[ { role: "dbOwner ",db: "{{ mongo.database_name }}" } 角色:[ { role: "readWrite ",db: "{{ mongo.database_name }}" } 我们使用conf文件提供凭证 数据: mongodb。u

  • 这并不困难,但它让我质疑spring auth服务器是最好的选择,还是我应该使用Keycloak?

  • 这是我使用SpringBoot的第一天,我试图理解体系结构,因此我开始构建一个hello world应用程序: 在我的pom.xml中,在maven-shade-plugin下,我将mainClass声明如下: 文件目标是src/main/java/com/demo/helloworld.java,该文件中的代码是: 我错过了什么?

  • 我有一个SpringBoot项目(maven/java8)。 我想通过Maven配置文件(dev.properties|prod.properties)过滤src/main/Resources/application.properties中的一些自定义变量 Maven命令: 应用属性: 开发属性: prod.properties: pom.xml:

  • 我想用SafetyNet验证电话号码Firebase,而不是重新CAPTCHA验证。我在这里遵循Firebase留档:https://firebase.google.com/docs/auth/android/phone-auth 在谷歌API控制台中,我启用了Android设备验证API 在Firebase控制台中,我添加了SHA-256指纹 重新安装谷歌服务。json并将其添加到项目中 它总是

  • 请帮帮我! 我到处找,但还是不明白。 我有域domain1.com,我想访问我的项目-快速启动-111111的“https://www.googleapis.com/auth/spreadsheetshttps://www.googleapis.com/auth/drive”范围。 我已经添加了我的域名,并通过DNS TXT记录进行验证 问题是为什么谷歌说“应用程序未验证”。我在哪里可以验证它?