简体   繁体   English

我可以通过“Spring Boot Maven Plugin”制作带有“build-info”的可执行 jar 吗?

[英]Can I make an executable jar with “build-info” by “Spring Boot Maven Plugin”?

I am trying to make an executable jar file with "Spring Boot Maven Plugin".我正在尝试使用“Spring Boot Maven Plugin”制作可执行的 jar 文件。

Usually, I can do this by setting "repackage".通常,我可以通过设置“重新打包”来做到这一点。 goal in my pom.xml file was set like this.我的 pom.xml 文件中的目标是这样设置的。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.2.6.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And my build command is like this:我的构建命令是这样的:

mvn clean package spring-boot:repackage

This works, but I want to have META-INF/build-info.properties in the jar file.这可行,但我想在 jar 文件中有META-INF/build-info.properties

By having this file, I can check build info in my springboot application, so I want to have it.通过拥有这个文件,我可以在我的 springboot 应用程序中检查构建信息,所以我想要它。

To generate " META-INF/build-info.properties " file, I need to set "build-info" goal.要生成“ META-INF/build-info.properties ”文件,我需要设置“build-info”目标。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.2.6.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>build-info</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Well now I am in a dilemma because好吧,现在我进退两难了,因为

  1. Setting "repackage" goal -> an executable jar without "META-INF/build-info.properties"设置“重新打包”目标 ->没有“META-INF/build-info.properties”的可执行jar
  2. Setting "build-info" goal -> an inexecutable jar with "META-INF/build-info.properties"设置“build-info”目标 -> 一个不可执行的 jar“META-INF/build-info.properties”

I want to have an executable jar with "META-INF/build-info.properties".我想要一个带有“META-INF/build-info.properties”的可执行jar。

I am pretty new to this maven process.我对这个 maven 过程很陌生。 Is there anyone who can help me?有谁能帮助我吗?


SOLVED解决了

I solved this issue.我解决了这个问题。 The problem was spring-boot-maven-plugin was in the wrong place.问题是spring-boot-maven-plugin放错了地方。 It was inside <pluginManagement> .它在<pluginManagement>里面。 I moved this plugin to <plugins>我将此插件移至<plugins>

Like @Mark Bramnik answered, I can set both goal settings in pom.xml, and mvn clean package command is enough!就像@Mark Bramnik 回答的那样,我可以在 pom.xml 中设置两个目标设置,并且mvn clean package命令就足够了!

You can run multiple goals of the same plugin.您可以运行同一个插件的多个目标。 So you can probably do something like this:所以你可能可以做这样的事情:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.2.6.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>build-info</goal>
            </goals>
        </execution>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 启动 maven 插件 - 如何构建可执行 jar 并包含运行它的脚本? - Spring Boot maven plugin - how do I build an executable jar and include a script to run it? 如何使用Maven插件正确构建Spring Boot far jar? - How to properly build a Spring Boot far jar using maven plugin? Spring Boot Maven plugin - How do I build a zip file with Java jar file and script to run it? - Spring Boot Maven plugin - How do I build a zip file with Java jar file and script to run it? Spring Boot + Gradle:如何构建可执行jar - Spring Boot + Gradle: how to build executable jar 无法在 Spring 引导上构建可执行 JAR - Unable to Build an executable JAR on Spring Boot 当我用Jenkins用Maven构建Spring Boot应用程序并执行JAR文件时,找不到类定义? - Can not find class define, when I build a Spring Boot application with Maven by Jenkins and execute JAR file? Spring Boot Maven无法建立可执行Jar,因为它正在寻找重复项 - Spring Boot Maven Won't Build Executable Jar because it's finding duplicates Spring Boot Maven 插件 - 重命名原始 JAR - Spring Boot Maven Plugin - rename original JAR 如何使用maven-jar-plugin和groovy构建可执行jar? - How to build executable jar using maven-jar-plugin and groovy? 如何使用 Spring Boot Gradle Plugin 2.1.* 构建不可执行的 jar(库) - How to build not executable jar (library) with Spring Boot Gradle Plugin 2.1.*
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM