英文:
maven-compiler-plugin could not found class in spring boot application
问题
我在我的Spring Boot应用程序中遇到了一个奇怪的问题。请帮助我找出原因,提前感谢!
描述
我的应用程序中有模块A和模块B,模块B是模块A的功能测试集,B依赖于模块A,所以我将A作为B的依赖项添加了进去。当我想进行功能测试时,我先运行应用程序A,然后在模块B中运行功能测试,一切正常。
但是当我运行 mvn clean install 时,模块B会在maven-compiler插件中引发异常,提示找不到从模块A引用的类,然而在我的IDE和运行时,它却正常工作。
有人能帮助我解决这个问题吗?谢谢
我尝试过更改pom.xml配置,并更改模块A依赖项的范围,但都没有奏效。
英文:
i had a strange issue in my spring boot application. Pls help me to found out the cause, thanks in advance!
Description
I had module A and module B in my application, module B is a set of functional tests for module A, B have dependencies in module A so i add A as a dependency of B. When i want to do functional tests, i ran application A and then run functional tests in module B, it works well.
But when i do mvn clean install, module B will raise exception in maven-compiler plugin, which says it could not found classes referenced from module A, while in my IDE and during runtime, it works fine.
Could anyone help me to figure out this question? thanks
i tried to change pom.xml configuration, and change scope of module A dependency, both did not work
答案1
得分: 1
问题已解决,未找到此类是由于 spring-boot-maven-plugin 的重新打包造成的,该插件将 Maven 构建的 JAR 文件重新打包成可部署为 Web 服务的 JAR 文件,但此 JAR 文件不能作为依赖项导入或使用,因此我们应该更改 spring-boot-maven-plugin 的配置,并生成两个 JAR 文件,一个用作依赖项,另一个用于部署。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
英文:
problem solved, this class not found is due to spring-boot-maven-plugin repackage, this plugin repackage maven build jar to a jar which can be deployed as web service, but this jar could not be imported or use as dependency, so we should change the spring-boot-maven-plugin configuration, and generate two jar, one is used as dependency and the other is used to deploy.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论