【发布时间】:2015-02-02 12:37:59
【问题描述】:
当项目的父POM因为它的孩子而使用打包模式POM时,是否可以使用Spring Boots Maven插件命令spring-boot:run?
我有一个带有“主”POM 的多模块 maven 项目,它是 Spring Boot 父模块的子模块。看起来像这样:
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<relativePath/>
</parent>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.example.module1.Application</start-class>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
这基本上是我们的“主” POM,每个孩子都将其用作父母。现在我们要从这个“主”POM 所在的工作目录执行spring-boot:run 命令。问题是,这会生成一个奇怪的ClassNotFoundException,因为module1(这个Application 类所在的位置)包含在POM 并作为一个模块提及。
使用单个模块 maven 项目和 <packaging>jar</packaging> 这将编译并运行 Application 类,因此不是 Spring-Boot 在这里无法正常工作。
在处理多模块 Maven 项目时,我必须进行哪些更改才能使其正常工作,还是根本无法使用 spring-boot-maven-plugin 插件?
旁注:我的应用程序类/模块 1 具有其他模块作为依赖项,因此在回答问题时请记住这一点。非常感谢任何有关如何改进这一点的建议。
【问题讨论】:
标签: java spring maven spring-boot