gpt4 book ai didi

java - Spring Boot maven 插件找不到主类,无法执行 java

转载 作者:搜寻专家 更新时间:2023-11-01 03:31:32 57 4
gpt4 key购买 nike

我有一个多模块 maven spring-boot maven 项目。其中一个子模块是一个 stub (一个 spring boot 应用程序),我想在 myRealApp 的集成测试期间启动然后停止。

Parent Pom
|
|----myRealApp module(spring boot app)
|----stub-of-some-remote-rest-api module(This is also a spring-boot app)

这是 pom 文件在模块 myRealApp 中的样子。其中也有所有的集成测试。它试图在集成测试阶段之前启动 stub 模块。但是当我在子模块目录中运行 maven 目标时出现错误:

 mvn integration-tests -X

Error: Could not find or load main class io.swagger.MyStub

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:run (start-boot) on project: Could not exec java

我可以在 Debug模式下看到工作目录设置正确。

myRealApp 的 Pom:

         <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
<executions>
<execution>
<configuration>
<workingDirectory>${project.parent.basedir}/module-of-my-stub/src/main/java</workingDirectory>
<mainClass>io.swagger.MyStub</mainClass>
</configuration>
<id>start-boot</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-boot</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>

</plugin>

也许我不允许在单独的执行中设置 workingDirectory,或者引用其他模块?

stub 就像我的应用程序所依赖的远程休息服务一样,我在开发过程中使用它,因为实际的远程服务的测试环境不可靠并且有一半时间停机。因此决定也在集成测试中使用它。

最佳答案

为了巩固一些针对问题的评论,这些基本上遵循了this other answer中的建议。 .

关键是针对 spring-boot-maven-plugin:run 目标将 classesDirectory 设置为指向 target\classes 目录在另一个项目下。

  <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
<executions>
<execution>
<id>start-stub</id>
<configuration>
<arguments>
<argument>--server.port=8090</argument>
</arguments>
<mainClass>io.swagger.Stub</mainClass>
<classesDirectory>../my-stub/target/classes</classesDirectory>
</configuration>
<goals>
<goal>start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>

<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>

关于java - Spring Boot maven 插件找不到主类,无法执行 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51874095/

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com