Maven 验证 Spring Boot 应用程序类的 ClassNotFoundException [英] Maven verify ClassNotFoundException for class of Spring Boot application

查看:92
本文介绍了Maven 验证 Spring Boot 应用程序类的 ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试为我的 Java Spring Boot 项目运行 Maven 的验证生命周期时,我收到一个 NoClassDefFoundError.它使用 mvn spring-boot:run 编译得很好,但是当我运行 mvn clean verify 时它失败了:

I'm getting a NoClassDefFoundError when I try to run verify lifecycle of Maven for my Java Spring Boot project. It compiles fine using mvn spring-boot:run but when I run mvn clean verify it fails thus:

$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

其中 com.fitforger.model.GymRat 是我的应用程序的类之一.

where com.fitforger.model.GymRat is one of the classes of my application.

项目结构:

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

我的 pom.xml 的相关部分:

Relevant bits of my pom.xml:

<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

推荐答案

OP 问题如下解决,

看起来与您面临的情况相似.你可以试试

This looks to be similar to what you are facing. Could you try with

<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
   <configuration>
        <classifier>exec</classifier>
   </configuration>
 </plugin>

这篇关于Maven 验证 Spring Boot 应用程序类的 ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆