带有 POM 封装聚合器的 Spring Boot [英] Spring Boot with POM packaging Agregator

查看:52
本文介绍了带有 POM 封装聚合器的 Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当项目的父POM因为它的孩子而使用打包模式POM时,是否可以使用Spring Boots Maven插件命令spring-boot:run?

Is it possible to use Spring Boots Maven plugin command spring-boot:run when the parent POM of the project is using packaging mode POM because of its children?

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

I have multi module maven project with a "master" POM that is in it's turn a child of the Spring Boot Parent module. Looking something like this:

    <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 中并作为模块提及.

This is basically our "master" POM which every child uses as it's parent. Now we want to perform the spring-boot:run command from the working directory this "master" POM is in. Problem is, this generates a ClassNotFoundException which is odd since module1 (where this Application class is located) is included in the POM and mentioned as a module.

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

Using a single module maven project and <packaging>jar</packaging> this compiles and runs the Application class so it is not Spring-Boot that is not working right here.

在处理多模块 Maven 项目时,我需要更改什么才能使其正常工作,还是根本无法使用 spring-boot-maven-plugin 插件?

What do I have to change to get this working or is it simply not possible to use the spring-boot-maven-plugin plugin when dealing with multi module Maven projects?

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

Sidenote: My Application class / Module 1 has the other modules as dependencies so keep this in mind when answering the question. Any suggestions on how to improve this are very appreciated.

推荐答案

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

It is not possible, as far as I know, because the plugin requires an executable jar to run.

spring-boot 插件 目标运行"说:

说明

运行一个可执行的归档应用程序

Run an executable archive application

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

Packaging pom is will not create an executable. It will only generate a pom.xml.

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

Try to run mvn install and look at the artifact deployed to your local repository:

我刚刚为一个带有包装 pom 的模块做了:

I just did for a module I have with packaging pom:

[INFO] Installing C:\projects\boot-parent\pom.xml to 
C:\Users\...\repository\no\boot-parent\0.0.1-SNAPSHOT\boot-parent-0.0.1-SNAPSHOT.pom

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

As you can see the artifact is boot-parent-0.0.1-SNAPSHOT.pom.

尝试将插件配置放在具有起始类(主类)和打包 jar 的模块 1 的 pom 中.

Try putting the plugin-configuration in the pom for module1 which has the start-class (main-class) and has packaging jar.

编辑您的评论:

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

Your comment suggests that you have issues with your client side Maven installation. Have a look at this answer. And especially the answer given by @ChristianAchilli.

我曾经通过删除本地存储库中相应的无法下载工件目录来解决此问题.下次运行 maven 命令时,再次触发工件下载.因此,我认为这是客户端设置.

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.

再次,希望这会有所帮助!

Again, hope this helps!

托马斯

这篇关于带有 POM 封装聚合器的 Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆