当我尝试为Java Spring项目运行验证Maven的生命周期时,出现一个奇怪的错误。请注意,它可以使用很好地编译,mvn spring- boot:run但是在我运行时mvn clean verify它会炸毁:
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
我的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问题,
这看起来与您所面临的相似。你可以尝试一下吗
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <classifier>exec</classifier> </configuration> </plugin>