加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 使用POM包装Agregator的Spring Boot

发布时间:2020-12-15 00:34:13 所属栏目:Java 来源:网络整理
导读:是否有可能使用 Spring Boots Maven插件命令spring-boot:当项目的父POM使用打包模式POM因为它的子节点时运行? 我有一个带有“主”POM的多模块maven项目,它是Spring Boot Parent模块的子项.看起来像这样: modelVersion4.0.0/modelVersion groupIdcom.examp
是否有可能使用 Spring Boots Maven插件命令spring-boot:当项目的父POM使用打包模式POM因为它的子节点时运行?

我有一个带有“主”POM的多模块maven项目,它是Spring Boot Parent模块的子项.看起来像这样:

<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,每个孩子都使用它作为它的父母.现在我们要从这个“master”POM所在的工作目录中执行spring-boot:run命令.问题是,这会产生一个奇怪的ClassNotFoundException,因为module1(这个Application类所在的位置)包含在POM中,作为模块提到.

使用单个模块maven项目和< packaging> jar< / packaging>这会编译并运行Application类,因此Spring-Boot不是在这里工作.

在处理多模块Maven项目时,我需要做些什么来改变它才能使用spring-boot-maven-plugin插件?

旁注:我的应用程序类/模块1将其他模块作为依赖项,因此在回答问题时请记住这一点.任何关于如何改进这一点的建议都非常感谢.

解决方法

据我所知,这是不可能的,因为插件需要一个可执行的jar来运行.

spring-boot plugin目标“运行”的文档说:

Description

Run an executable archive application

包装pom不会创建可执行文件.它只会生成一个pom.xml.

尝试运行mvn install并查看部署到本地存储库的工件:

我刚刚为包装pom的模块做了一件事:

[INFO] Installing C:projectsboot-parentpom.xml to 
C:Users...repositorynoboot-parent.0.1-SNAPSHOTboot-parent-0.0.1-SNAPSHOT.pom

如您所见,工件是boot-parent-0.0.1-SNAPSHOT.pom.

尝试将插件配置放在具有start-class(main-class)并具有打包jar的module1的pom中.

编辑您的评论:

您的评论表明您的客户端Maven安装存在问题.看看this answer.尤其是@ChristianAchilli给出的答案.

I use to solve this issue by deleting the corresponding failed to download artifact directory in my local repo. Next time I run the maven command the artifact download is triggered again. Therefore I’d say it’s a client side setting.

再次,希望这有帮助!

托马斯

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读